/* ============================================================
   VDV Troubleshooter — Brand CSS
   Brand colors: blue-dark #1a3a56 | blue #1e3a5f | lime #8dc63f | orange #e8650a
   Font: Outfit (Google Fonts)
   ============================================================ */

/* ---- Variables ---- */
:root {
    --blue-dark:  #1a3a56;
    --blue:       #1e3a5f;
    --lime:       #8dc63f;
    --orange:     #e8650a;
    --white:      #ffffff;
    --gray-50:    #f8f9fa;
    --gray-100:   #f0f2f5;
    --gray-200:   #e2e8f0;
    --gray-400:   #94a3b8;
    --gray-600:   #475569;
    --gray-800:   #1e293b;
    --danger:     #dc2626;
    --success:    #16a34a;

    --sidebar-width: 240px;
    --topbar-height: 60px;
    --radius:     8px;
    --radius-lg:  12px;
    --shadow:     0 1px 4px rgba(0,0,0,.12);
    --shadow-md:  0 4px 16px rgba(0,0,0,.14);

    /* Semantic aliases used across components */
    --surface:    #ffffff;
    --border:     #e2e8f0;
    --text:       #1e293b;
    --muted:      #64748b;
    --blue-mid:   #2d5a8e;
}

/* ---- Reset / Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: 'Outfit', system-ui, sans-serif;
    font-size: 15px;
    color: var(--gray-800);
    background: var(--gray-100);
    line-height: 1.5;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; display: block; }

/* ---- Top bar (public pages) ---- */
.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    min-height: var(--topbar-height);
    background: var(--blue-dark);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .5rem 1rem;
    z-index: 100;
    box-shadow: var(--shadow-md);
    flex-wrap: wrap;
    gap: .5rem;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-shrink: 0;
}

.topbar-vlogo {
    height: 28px;
    width: auto;
    flex-shrink: 0;
}

.topbar-title {
    font-weight: 600;
    font-size: 1.1rem;
    letter-spacing: -.01em;
    white-space: nowrap;
}

.topbar-nav {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}

@media (max-width: 480px) {
    .topbar {
        padding: .4rem .75rem;
    }
    .topbar-title {
        font-size: .95rem;
    }
    .topbar-nav {
        gap: .4rem;
    }
    .lang-btn {
        padding: 3px 7px;
        font-size: .72rem;
    }
    .btn-sm {
        padding: .25rem .6rem;
        font-size: .78rem;
    }
}

/* ---- Language switch ---- */
.lang-switch {
    display: flex;
    gap: 2px;
    background: rgba(255,255,255,.1);
    border-radius: var(--radius);
    padding: 2px;
}

.lang-btn {
    padding: 4px 10px;
    border-radius: 6px;
    font-size: .8rem;
    font-weight: 600;
    color: rgba(255,255,255,.7);
    text-transform: uppercase;
    transition: background .15s, color .15s;
    text-decoration: none;
}

.lang-btn:hover { background: rgba(255,255,255,.15); color: var(--white); text-decoration: none; }
.lang-btn.active { background: var(--lime); color: var(--blue-dark); }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .55rem 1.2rem;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: .9rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: background .15s, box-shadow .15s, opacity .15s;
    text-decoration: none;
}

.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary   { background: var(--lime);    color: var(--blue-dark); }
.btn-primary:hover   { background: #7db535; }
.btn-secondary { background: var(--blue);   color: var(--white); }
.btn-secondary:hover { background: var(--blue-dark); }
.btn-danger    { background: var(--danger);  color: var(--white); }
.btn-danger:hover    { background: #b91c1c; }
.btn-ghost     { background: rgba(255,255,255,.1); color: var(--white); }
.btn-ghost:hover     { background: rgba(255,255,255,.2); }
.btn-login     { background: var(--lime); color: var(--blue-dark); font-weight: 700; }
.btn-login:hover     { background: #7db535; }
.btn-logout    { background: rgba(255,255,255,.15); color: var(--white); }
.btn-logout:hover    { background: rgba(255,255,255,.25); }
.btn-outline   { background: transparent; border: 1.5px solid var(--blue); color: var(--blue); }
.btn-outline:hover   { background: var(--blue); color: var(--white); }

.btn-sm  { padding: .35rem .8rem; font-size: .82rem; }
.btn-full { width: 100%; justify-content: center; }

/* ---- Flash messages ---- */
.flash-container {
    position: fixed;
    top: calc(var(--topbar-height) + .75rem);
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    min-width: 300px;
    max-width: 520px;
}

.flash {
    padding: .75rem 1.25rem;
    border-radius: var(--radius);
    font-weight: 500;
    box-shadow: var(--shadow-md);
}

.flash-error   { background: #fee2e2; color: var(--danger); border-left: 4px solid var(--danger); }
.flash-success { background: #dcfce7; color: var(--success); border-left: 4px solid var(--success); }
.flash-info    { background: #dbeafe; color: #1d4ed8; border-left: 4px solid #1d4ed8; }

/* ---- Main content (public) ---- */
.main-content {
    margin-top: var(--topbar-height);
    min-height: calc(100vh - var(--topbar-height));
}

/* ============================================================
   LOGIN PAGE
   ============================================================ */

.login-body {
    background: var(--blue-dark);
}

.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - var(--topbar-height));
    padding: 2rem 1rem;
}

.login-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-md);
}

.login-logo {
    text-align: center;
    margin-bottom: 1.25rem;
}

.login-logo img {
    height: 52px;
    margin: 0 auto;
}

.login-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--blue-dark);
    text-align: center;
    margin-bottom: .25rem;
}

.login-subtitle {
    font-size: 1rem;
    font-weight: 400;
    color: var(--gray-600);
    text-align: center;
    margin-bottom: 1.75rem;
}

.login-error {
    background: #fee2e2;
    color: var(--danger);
    border-left: 4px solid var(--danger);
    padding: .65rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
    font-size: .9rem;
}

.login-form .form-group + .form-group { margin-top: .9rem; }

/* ---- Form group ---- */
.form-group {
    display: flex;
    flex-direction: column;
    gap: .35rem;
}

.form-group label {
    font-weight: 500;
    font-size: .88rem;
    color: var(--gray-600);
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: .6rem .85rem;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: .95rem;
    color: var(--gray-800);
    background: var(--white);
    transition: border-color .15s;
    outline: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--lime);
    box-shadow: 0 0 0 3px rgba(141,198,63,.2);
}

.login-form .btn-primary {
    margin-top: 1.4rem;
}

/* ============================================================
   OPERATOR (INDEX) PAGE
   ============================================================ */

.operator-body {
    background: var(--gray-100);
}

.operator-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.operator-header {
    text-align: center;
    margin-bottom: 2rem;
}

.operator-logo {
    height: 48px;
    width: auto;
    margin: 0 auto 1rem;
}

.operator-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--blue-dark);
}

.operator-hint {
    color: var(--gray-600);
    margin-top: .4rem;
}

/* Machine grid */
.machine-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.machine-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: box-shadow .2s, transform .2s;
    text-decoration: none;
    color: inherit;
    border: 2px solid transparent;
}

.machine-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    border-color: var(--lime);
    text-decoration: none;
}

.machine-card-img img {
    width: 100%;
    height: 120px;
    object-fit: cover;
}

.machine-card-icon {
    font-size: 3rem;
    text-align: center;
    padding: 1.2rem 0 .5rem;
    color: var(--blue);
}

.machine-card-info {
    padding: .75rem 1rem 1rem;
    display: flex;
    flex-direction: column;
    gap: .2rem;
}

.machine-card-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--blue-dark);
}

.machine-card-loc,
.machine-card-nr {
    font-size: .82rem;
    color: var(--gray-600);
}

.operator-footer {
    margin-top: 3rem;
    text-align: center;
}

/* ============================================================
   ADMIN LAYOUT
   ============================================================ */

.admin-body {
    background: var(--gray-100);
}

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

/* ---- Sidebar ---- */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--blue-dark);
    color: var(--white);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 50;
    box-shadow: 2px 0 8px rgba(0,0,0,.15);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,.1);
}

.sidebar-logo-img {
    height: 32px;
    width: auto;
}

.sidebar-brand {
    font-weight: 700;
    font-size: .95rem;
    letter-spacing: -.01em;
}

.sidebar-nav {
    flex: 1;
    padding: .75rem 0;
    display: flex;
    flex-direction: column;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .7rem 1.25rem;
    color: rgba(255,255,255,.75);
    font-size: .92rem;
    font-weight: 500;
    text-decoration: none;
    transition: background .15s, color .15s;
}

.sidebar-link:hover {
    background: rgba(255,255,255,.08);
    color: var(--white);
    text-decoration: none;
}

.sidebar-link.active {
    background: rgba(141,198,63,.15);
    color: var(--lime);
    border-right: 3px solid var(--lime);
}

.sidebar-icon {
    font-size: 1.1rem;
    width: 1.3rem;
    text-align: center;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,.1);
}

.sidebar-user {
    display: flex;
    flex-direction: column;
    gap: .3rem;
}

.sidebar-user-name {
    font-size: .85rem;
    font-weight: 600;
    color: var(--white);
}

.sidebar-logout {
    font-size: .8rem;
    color: rgba(255,255,255,.5);
}

.sidebar-logout:hover {
    color: var(--lime);
    text-decoration: none;
}

/* ---- Admin main ---- */
.admin-main {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.admin-topbar {
    height: var(--topbar-height);
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.75rem;
    position: sticky;
    top: 0;
    z-index: 40;
    box-shadow: var(--shadow);
}

.admin-topbar-title {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--blue-dark);
}

.admin-topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Override lang-switch colors for white topbar */
.admin-topbar .lang-switch {
    background: var(--gray-100);
}

.admin-topbar .lang-btn {
    color: var(--gray-600);
}

.admin-topbar .lang-btn:hover {
    background: var(--gray-200);
    color: var(--blue-dark);
}

.admin-topbar .lang-btn.active {
    background: var(--lime);
    color: var(--blue-dark);
}

.admin-content {
    padding: 1.75rem;
    flex: 1;
}

/* ---- Data table ---- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--white);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.data-table thead {
    background: var(--blue-dark);
    color: var(--white);
}

.data-table th {
    padding: .75rem 1rem;
    text-align: left;
    font-weight: 500;
    font-size: .88rem;
    letter-spacing: .02em;
    text-transform: uppercase;
}

.data-table td {
    padding: .7rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    font-size: .93rem;
    vertical-align: middle;
}

.data-table tbody tr:last-child td { border-bottom: none; }

.data-table tbody tr:hover { background: var(--gray-50); }

.actions-cell { text-align: right; }

/* ---- Badges ---- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: .2rem .65rem;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 600;
}

.badge-green  { background: #dcfce7; color: var(--success); }
.badge-red    { background: #fee2e2; color: var(--danger); }
.badge-orange { background: #ffedd5; color: var(--orange); }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }

/* ---- Stats grid ---- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .5rem;
    text-align: center;
}

.stat-icon {
    font-size: 2rem;
    color: var(--blue);
}

.stat-value {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--blue-dark);
    line-height: 1;
}

.stat-label {
    font-size: .9rem;
    color: var(--gray-600);
}

/* ---- Empty state ---- */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--gray-600);
}

.empty-icon {
    font-size: 3.5rem;
    margin-bottom: 1rem;
    opacity: .4;
}

/* ---- Page actions ---- */
.page-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1.25rem;
}

/* ---- Tab bar ---- */
.tab-bar-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    gap: 1rem;
    flex-wrap: wrap;
}
.tab-bar {
    display: flex;
    gap: 2px;
    background: var(--gray-200);
    border-radius: var(--radius);
    padding: 3px;
}
.tab-btn {
    padding: .4rem 1rem;
    border-radius: 6px;
    font-size: .88rem;
    font-weight: 500;
    color: var(--gray-600);
    text-decoration: none;
    transition: background .15s, color .15s;
}
.tab-btn:hover { background: rgba(0,0,0,.05); text-decoration: none; }
.tab-btn.active { background: var(--white); color: var(--blue-dark); box-shadow: var(--shadow); }

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        min-height: unset;
        height: auto;
        position: relative;
    }

    .admin-layout {
        flex-direction: column;
    }

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

    .machine-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }

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

    .login-card {
        padding: 1.75rem 1.25rem;
    }

    .data-table th:nth-child(n+4),
    .data-table td:nth-child(n+4) {
        display: none;
    }
}

/* Decision tree styles */
.back-link { color: var(--blue-mid); text-decoration: none; display: inline-block; margin-bottom: 12px; }
.tree-breadcrumb { font-size: 13px; color: var(--muted); margin-bottom: 16px; }
.tree-breadcrumb a { color: var(--blue-mid); text-decoration: none; }
.tree-question h2 { font-size: 20px; margin-bottom: 16px; }
.tree-image { max-width: 100%; border-radius: var(--radius); margin: 12px 0; }
.tree-options { display: flex; flex-direction: column; gap: 8px; }
.tree-option { display: block; padding: 14px 16px; background: #fffbeb; border: 2px solid #fde68a; border-radius: 8px; text-decoration: none; color: var(--text); font-weight: 500; }
.tree-option:hover { background: #fef3c7; }
.solution-card { background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 12px; padding: 20px; }
.solution-header { font-weight: 700; font-size: 18px; color: #166534; margin-bottom: 12px; }
.solution-text { line-height: 1.6; white-space: pre-line; }
.escalation-card { background: #fef2f2; border: 1px solid #fecaca; border-radius: 12px; padding: 20px; }
.escalation-header { font-weight: 700; font-size: 18px; color: #991b1b; margin-bottom: 12px; }

/* AI Search */
.ai-search-box { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 2px solid var(--blue); border-radius: 12px; padding: 12px 16px; margin-bottom: 4px; }
.ai-search-icon { font-size: 24px; }
.ai-search-input { flex: 1; border: none; outline: none; font-size: 15px; font-family: inherit; background: transparent; }
.ai-search-btn { background: var(--blue); color: white; border: none; border-radius: 8px; padding: 8px 16px; font-weight: 600; cursor: pointer; font-family: inherit; }
.ai-hint { font-size: 12px; color: var(--blue-mid); margin-bottom: 16px; margin-left: 4px; }

/* AI Results */
.ai-results { background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 12px; padding: 16px; margin-bottom: 20px; }
.ai-results-header { font-weight: 700; color: var(--blue); margin-bottom: 12px; font-size: 16px; }
.ai-disclaimer {
    background: #fef3c7;
    border: 1px solid #fbbf24;
    border-radius: 6px;
    padding: .5rem .75rem;
    font-size: .82rem;
    color: #92400e;
    margin-bottom: .75rem;
    line-height: 1.4;
}
.ai-response-body { line-height: 1.6; font-size: 14px; }
.kb-header { font-weight: 600; margin-top: 16px; padding-top: 12px; border-top: 1px solid #bfdbfe; }
.kb-verified { color: #166534; }
.kb-entry { background: white; border-radius: 8px; padding: 12px; margin-top: 8px; }
.kb-entry strong { font-size: 14px; }
.kb-entry p { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* Categories */
.category-list { display: flex; flex-direction: column; gap: 10px; }
.category-card { display: flex; align-items: center; gap: 16px; background: var(--surface); border: 2px solid var(--border); border-radius: 12px; padding: 16px; text-decoration: none; color: var(--text); }
.category-card.secondary { border-width: 1px; padding: 14px 16px; opacity: 0.7; }
.category-card.sub { border-width: 1px; }
.cat-icon { font-size: 28px; min-width: 40px; text-align: center; }
.cat-name { font-weight: 700; font-size: 15px; }
.category-card .arrow { margin-left: auto; color: var(--muted); }
/* ---- Photo upload ---- */
.photo-upload-row {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin: .75rem 0;
}
.photo-upload-btn {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem 1rem;
    background: var(--surface);
    border: 2px dashed var(--gray-200);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: .88rem;
    color: var(--gray-600);
    transition: border-color .15s, background .15s;
}
.photo-upload-btn:hover {
    border-color: var(--blue);
    background: var(--gray-50);
}
.photo-preview {
    display: flex;
    align-items: center;
    gap: .5rem;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 4px;
}
.photo-preview img {
    height: 48px;
    width: 48px;
    object-fit: cover;
    border-radius: 4px;
}
.photo-remove-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--gray-400);
    cursor: pointer;
    padding: 0 .4rem;
}
.photo-remove-btn:hover { color: var(--danger); }

/* ---- Machine properties (troubleshoot page) ---- */
.machine-props {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    margin-bottom: 1.25rem;
}
.machine-prop {
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    padding: .25rem .6rem;
    font-size: .78rem;
    color: var(--gray-600);
    white-space: nowrap;
}
.machine-prop strong {
    color: var(--blue-dark);
}

.tree-link { display: block; padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; margin-top: 8px; text-decoration: none; color: var(--text); font-weight: 500; }

/* Stats dashboard */
.stat-card { background: var(--surface); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); text-align: center; }
.stat-card.highlight { border: 2px solid var(--orange); }
.stat-number { font-size: 32px; font-weight: 700; color: var(--blue); }
.stat-label { font-size: 13px; color: var(--muted); margin-top: 4px; }
