:root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --danger: #dc3545;
    --warning: #ffc107;
    --success: #28a745;
    --info: #17a2b8;
    --bg: #f4f6f9;
    --card-bg: #ffffff;
    --text: #333;
    --text-muted: #6c757d;
    --border: #dee2e6;
    --sidebar-bg: #1e293b;
    --sidebar-text: #e2e8f0;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    position: fixed;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-header {
    padding: 1.5rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
}

.nav-menu {
    list-style: none;
    padding: 0.5rem 0;
}

.nav-link {
    display: block;
    padding: 0.75rem 1.25rem;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: background 0.2s;
    font-size: 0.95rem;
}

.nav-link:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.main-content {
    flex: 1;
    margin-left: 240px;
}

.top-bar {
    background: var(--card-bg);
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.top-bar h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.page-content {
    padding: 2rem;
}

.card {
    background: var(--card-bg);
    border-radius: 8px;
    border: 1px solid var(--border);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.card-title {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.card-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text);
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.table-container { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th {
    text-align: left;
    padding: 0.75rem 1rem;
    background: #f8f9fa;
    border-bottom: 2px solid var(--border);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

tr:hover { background: #f8f9fa; }

.badge {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-critical { background: #fee2e2; color: #dc2626; }
.badge-high { background: #ffedd5; color: #ea580c; }
.badge-medium { background: #fef3c7; color: #d97706; }
.badge-low { background: #dbeafe; color: #2563eb; }
.badge-new { background: #e0e7ff; color: #4338ca; }
.badge-open, .badge-inprogress { background: #dbeafe; color: #2563eb; }
.badge-resolved { background: #d1fae5; color: #059669; }
.badge-closed { background: #e5e7eb; color: #6b7280; }
.badge-approved { background: #d1fae5; color: #059669; }
.badge-rejected { background: #fee2e2; color: #dc2626; }
.badge-failed { background: #fee2e2; color: #dc2626; }
.badge-completed { background: #d1fae5; color: #059669; }
.badge-draft { background: #f3f4f6; color: #6b7280; }

.form-group { margin-bottom: 1rem; }

.form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 0.35rem;
    color: var(--text);
}

input[type="text"],
input[type="number"],
input[type="datetime-local"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    transition: border-color 0.2s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,115,232,0.1);
}

textarea { min-height: 100px; resize: vertical; }

.btn {
    display: inline-block;
    padding: 0.5rem 1.25rem;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-secondary { background: #6c757d; color: #fff; }
.btn-sm { padding: 0.3rem 0.75rem; font-size: 0.8rem; }

.btn-group { display: flex; gap: 0.5rem; margin: 1rem 0; }

.metric-bar {
    height: 8px;
    background: #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
    margin-top: 0.5rem;
}

.metric-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s;
}

.metric-bar-fill.green { background: var(--success); }
.metric-bar-fill.yellow { background: var(--warning); }
.metric-bar-fill.red { background: var(--danger); }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.section-header h2 { font-size: 1.4rem; }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.field-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}

.field-value {
    font-size: 0.95rem;
    margin-bottom: 1rem;
}

.notes-list { margin-top: 1rem; }

.note-item {
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 0.5rem;
}

.note-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

.filter-bar {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    align-items: end;
}

.filter-bar select {
    width: auto;
    min-width: 150px;
}

/* AI Resolution Assistant */
.ai-analysis-card {
    border-left: 4px solid var(--primary);
}

.ai-summary {
    background: #f0f4ff;
    border-radius: 6px;
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text);
}

.ai-recommendation {
    background: #e8f5e9;
    border-radius: 6px;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.ai-steps {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.ai-step {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    padding: 0.6rem 0.8rem;
    background: var(--bg);
    border-radius: 6px;
}

.ai-step-num {
    min-width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.ai-suggestion {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1rem;
    margin-bottom: 0.75rem;
}

.ai-suggestion-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.ai-suggestion-title {
    font-weight: 600;
    font-size: 0.95rem;
}

.ai-confidence {
    font-size: 0.8rem;
}

.ai-suggestion-source {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.ai-resolution-text {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.75rem;
    font-family: inherit;
    font-size: 0.9rem;
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.5;
    max-height: 200px;
    overflow-y: auto;
}

/* System Configuration */
.config-overview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.config-card {
    transition: box-shadow 0.2s, border-color 0.2s;
}

.config-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.config-card-active {
    border-color: var(--success);
    border-left: 4px solid var(--success);
}

.config-card-header {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    margin-bottom: 0.75rem;
}

.config-icon {
    font-size: 1.75rem;
    line-height: 1;
    flex-shrink: 0;
}

.config-card-status {
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}

.config-editor {
    border-left: 4px solid var(--primary);
    margin-top: 1rem;
}

.config-editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
}

.config-toggle-row {
    background: var(--bg);
    border-radius: 6px;
    padding: 0.75rem 1rem;
    margin-bottom: 1.25rem;
}

.config-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    cursor: pointer;
}

.config-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--success);
}

.config-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem 1.5rem;
    margin-bottom: 1.5rem;
}

@media (max-width: 800px) {
    .config-fields {
        grid-template-columns: 1fr;
    }
}

.config-field label {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

.config-field input,
.config-field select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    background: #fff;
}

.config-field input:focus,
.config-field select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,115,232,0.1);
}

.config-required {
    color: var(--danger);
    margin-left: 2px;
}

.config-help {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    line-height: 1.4;
}

.config-actions {
    display: flex;
    gap: 0.75rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.config-instructions {
    margin-top: 1.5rem;
    background: #f8f9ff;
    border-radius: 6px;
    padding: 1rem 1.25rem;
}

.config-instructions h4 {
    margin: 0 0 0.75rem;
    color: var(--primary-dark);
}

.config-instructions ol {
    padding-left: 1.25rem;
    margin: 0;
}

.config-instructions li {
    margin-bottom: 0.5rem;
    line-height: 1.5;
    font-size: 0.9rem;
}

.config-instructions code {
    background: #e8edf4;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-size: 0.85em;
}

/* Role assignment layout */
.role-assign-layout {
    display: grid;
    grid-template-columns: minmax(340px, 1fr) minmax(220px, 280px);
    gap: 1rem;
}

/* Google Places Autocomplete styling */
.address-autocomplete-container {
    width: 100%;
    min-height: 38px;
    position: relative;
}

.address-autocomplete-container gmp-place-autocomplete {
    width: 100% !important;
    display: block !important;
}

/* Style the internal input of PlaceAutocompleteElement */
.address-autocomplete-container gmp-place-autocomplete input,
.address-autocomplete-container gmp-place-autocomplete [part="input"] {
    width: 100% !important;
    padding: 0.375rem 0.75rem !important;
    font-size: 1rem !important;
    font-weight: 400 !important;
    line-height: 1.5 !important;
    color: #212529 !important;
    background-color: #fff !important;
    border: 1px solid #ced4da !important;
    border-radius: 0.375rem !important;
    box-sizing: border-box !important;
}

.address-autocomplete-container gmp-place-autocomplete input:focus,
.address-autocomplete-container gmp-place-autocomplete [part="input"]:focus {
    border-color: #86b7fe !important;
    outline: 0 !important;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25) !important;
}

.address-autocomplete-container input {
    width: 100%;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: #212529;
    background-color: #fff;
    border: 1px solid #ced4da;
    border-radius: 0.375rem;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.address-autocomplete-container input:focus {
    color: #212529;
    background-color: #fff;
    border-color: #86b7fe;
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}
    margin-bottom: 1rem;
    align-items: start;
}

.role-user-picker {
    min-width: 0;
}

.role-user-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.4rem;
    flex-wrap: wrap;
}

.role-user-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.role-user-search {
    width: 100%;
    margin-bottom: 0.5rem;
}

.role-toggle-disabled {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
}

.role-user-summary {
    color: var(--text-muted);
}

.role-user-list {
    max-height: 220px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.25rem;
    background: var(--card-bg);
}

.role-user-result {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border: none;
    background: transparent;
    text-align: left;
    padding: 0.45rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
}

.role-user-result:hover {
    background: #f8f9fa;
}

.role-selected-user {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #f8f9fa;
}

.role-assign-controls {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.role-assign-submit {
    width: 100%;
    min-height: 38px;
}

@media (max-width: 1000px) {
    .role-assign-layout {
        grid-template-columns: 1fr;
    }

    .role-assign-submit {
        width: auto;
    }
}

/* ============================================
   MOBILE RESPONSIVE STYLES
   ============================================ */

/* Mobile Menu Toggle Button */
.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    margin-right: 0.5rem;
}

/* Overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
}

.sidebar-overlay.active {
    display: block;
}

/* Mobile Breakpoint - Tablets and smaller */
@media (max-width: 992px) {
    .mobile-menu-toggle {
        display: block;
    }

    /* Show close button in sidebar on mobile */
    .sidebar .mobile-menu-toggle {
        display: block !important;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 999;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .page-content {
        padding: 1rem;
    }

    .top-bar {
        padding: 0.75rem 1rem;
    }

    .top-bar h1 {
        font-size: 1rem;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .section-header h2 {
        font-size: 1.2rem;
    }

    .form-row,
    .detail-grid {
        grid-template-columns: 1fr;
    }

    .card-grid {
        grid-template-columns: 1fr 1fr;
    }

    .filter-bar {
        flex-wrap: wrap;
    }

    .filter-bar select {
        min-width: 120px;
    }

    .role-assign-layout {
        grid-template-columns: 1fr;
    }

    /* Hide department name on mobile header */
    .dept-name-mobile-hide {
        display: none !important;
    }

    /* Stack 2-column grids on tablets */
    div[style*="grid-template-columns:2fr 1fr"],
    div[style*="grid-template-columns: 2fr 1fr"],
    div[style*="grid-template-columns:1fr 380px"],
    div[style*="grid-template-columns: 1fr 380px"] {
        display: flex !important;
        flex-direction: column !important;
    }
}

/* Mobile Breakpoint - Phones */
@media (max-width: 576px) {
    .card-grid {
        grid-template-columns: 1fr;
    }

    .card {
        padding: 1rem;
    }

    .card-value {
        font-size: 1.5rem;
    }

    .page-content {
        padding: 0.75rem;
    }

    .top-bar {
        padding: 0.5rem 0.75rem;
    }

    .top-bar h1 {
        font-size: 0.9rem;
    }

    /* Hide non-essential columns on mobile */
    .mobile-hide {
        display: none !important;
    }

    /* Stack user info */
    .user-info-desktop {
        display: none !important;
    }

    .user-avatar-mobile {
        width: 36px !important;
        height: 36px !important;
        font-size: 0.85rem !important;
    }

    /* Responsive tables */
    .table-responsive-mobile {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        font-size: 0.8rem;
    }

    th, td {
        padding: 0.5rem 0.75rem;
        white-space: nowrap;
    }

    /* Buttons */
    .btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }

    .btn-group {
        flex-wrap: wrap;
    }

    /* Forms */
    input[type="text"],
    input[type="number"],
    input[type="datetime-local"],
    input[type="date"],
    select,
    textarea {
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    /* Modals */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal-body {
        padding: 1rem;
    }

    /* Filter bar */
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-bar select {
        width: 100%;
        min-width: auto;
    }

    /* Section headers */
    .section-header .btn-group,
    .section-header .d-flex {
        width: 100%;
        flex-wrap: wrap;
    }

    .section-header .btn {
        flex: 1;
        min-width: 100px;
    }

    /* Detail page grids - make them stack */
    div[style*="grid-template-columns:2fr 1fr"],
    div[style*="grid-template-columns: 2fr 1fr"],
    div[style*="grid-template-columns:1fr 380px"],
    div[style*="grid-template-columns: 1fr 380px"],
    div[style*="grid-template-columns:1fr 1fr"],
    div[style*="grid-template-columns: 1fr 1fr"] {
        display: flex !important;
        flex-direction: column !important;
    }

    /* Section header responsive - stack content */
    .section-header {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.75rem !important;
    }

    .section-header > div {
        flex-wrap: wrap !important;
    }

    .section-header h2 {
        font-size: 1.1rem !important;
        white-space: normal !important;
    }

    /* Mobile-friendly inline filters */
    .section-header input[type="text"],
    .section-header select {
        min-width: 0 !important;
        width: auto !important;
        flex: 1 1 45% !important;
        height: 36px !important;
        font-size: 14px !important;
    }

    /* Table header mobile adjustments */
    table th {
        font-size: 0.75rem;
        padding: 0.4rem 0.5rem;
    }

    /* Horizontal scroll for wide tables */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    .nav-link {
        padding: 1rem 1.25rem;
    }

    .btn {
        min-height: 44px;
        min-width: 44px;
    }

    .btn-sm {
        min-height: 36px;
    }

    input, select, textarea {
        min-height: 44px;
    }

    /* Larger tap targets */
    .table tbody td {
        min-height: 44px;
    }
}

/* Landscape phone orientation */
@media (max-height: 500px) and (orientation: landscape) {
    .sidebar {
        width: 200px;
    }

    .nav-link {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }

    .page-content {
        padding: 0.5rem 1rem;
    }
}

/* Print styles */
@media print {
    .sidebar,
    .mobile-menu-toggle,
    .top-bar {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
    }

    .page-content {
        padding: 0 !important;
    }
}
