/* ============================================================
   EMIS — Main Stylesheet
   Aesthetic: Industrial utilitarian — dark steel, amber accents,
   monospaced data, tight grids. Designed for shop & field use.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=Sora:wght@300;400;600&display=swap');

/* ---- Variables ---- */
:root {
    --bg:        #0f1012;
    --bg2:       #161719;
    --surface:   #1c1e21;
    --surface2:  #23262a;
    --border:    rgba(255,255,255,.09);
    --border2:   rgba(255,255,255,.16);
    --text:      #e2e0d8;
    --muted:     #737068;
    --muted2:    #9a9690;
    --accent:    #e8a020;       /* Amber */
    --accent2:   #c47d10;
    --green:     #3db37a;
    --red:       #e05252;
    --blue:      #4a9fd4;
    --orange:    #e06a30;
    --radius:    3px;
    --radius-lg: 6px;
    --font-body: 'Sora', system-ui, sans-serif;
    --font-mono: 'IBM Plex Mono', 'Courier New', monospace;
    --nav-w:     230px;
    --top-h:     52px;
    --shadow:    0 2px 12px rgba(0,0,0,.5);
}

/* ---- Light Theme ---- */
[data-theme="light"] {
    --bg:        #f2f0ec;
    --bg2:       #e8e6e0;
    --surface:   #ffffff;
    --surface2:  #f2f0ec;
    --border:    rgba(0,0,0,.10);
    --border2:   rgba(0,0,0,.18);
    --text:      #1a1a16;
    --muted:     #8a8780;
    --muted2:    #6a6760;
    --accent:    #b87310;
    --accent2:   #9a5f0a;
    --green:     #2a8f5c;
    --red:       #c23535;
    --blue:      #3a80b5;
    --orange:    #c05620;
    --shadow:    0 2px 12px rgba(0,0,0,.12);
}

/* ---- System preference auto-switch (if user hasn't manually chosen) ---- */
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]):not([data-theme="light"]) {
        --bg:        #f2f0ec;
        --bg2:       #e8e6e0;
        --surface:   #ffffff;
        --surface2:  #f2f0ec;
        --border:    rgba(0,0,0,.10);
        --border2:   rgba(0,0,0,.18);
        --text:      #1a1a16;
        --muted:     #8a8780;
        --muted2:    #6a6760;
        --accent:    #b87310;
        --accent2:   #9a5f0a;
        --green:     #2a8f5c;
        --red:       #c23535;
        --blue:      #3a80b5;
        --orange:    #c05620;
        --shadow:    0 2px 12px rgba(0,0,0,.12);
    }
}

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

html {
    height: 100%;
    scroll-behavior: smooth;
}
body {
    min-height: 100%;
    font-family: var(--font-body);
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

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

/* ============================================================
   LAYOUT
   ============================================================ */
.app-layout {
    display: grid;
    grid-template-columns: var(--nav-w) 1fr;
    grid-template-rows: var(--top-h) 1fr;
    height: 100vh;
    overflow: hidden;
}

.app-topbar {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    padding: 0 20px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    gap: 16px;
    z-index: 100;
}

.app-logo {
    font-family: var(--font-mono);
    font-weight: 500;
    font-size: 15px;
    color: var(--accent);
    letter-spacing: -.5px;
    white-space: nowrap;
    margin-right: 8px;
}

.app-topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-badge {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px; height: 32px;
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--muted2);
    transition: color .15s, background .15s;
}
.topbar-badge:hover { color: var(--text); background: var(--surface2); }
.topbar-badge .count {
    position: absolute;
    top: -4px; right: -6px;
    min-width: 18px; height: 18px;
    padding: 0 5px;
    background: var(--red);
    border-radius: 9px;
    border: 2px solid var(--bg2);
    font-size: 10px;
    font-weight: 700;
    line-height: 14px;
    color: #fff;
    align-items: center;
    justify-content: center;
    display: flex;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px 4px 4px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background .15s;
    font-size: 12px;
}
.user-chip:hover { background: var(--surface2); }
.user-chip .avatar {
    width: 28px; height: 28px;
    border-radius: var(--radius);
    background: var(--accent2);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 12px; color: #000;
}

/* ---- Sidebar ---- */
.app-sidebar {
    background: var(--bg2);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 0;
    display: flex;
    flex-direction: column;
}

/* Sidebar backdrop overlay (mobile) */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 150;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
    -webkit-tap-highlight-color: transparent;
}
.sidebar-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--muted);
    padding: 16px 16px 4px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    color: var(--muted2);
    font-size: 13px;
    font-weight: 400;
    border-left: 2px solid transparent;
    transition: color .15s, border-color .15s, background .15s;
    cursor: pointer;
}
.nav-link svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-link:hover { color: var(--text); background: var(--surface); }
.nav-link.active { color: var(--accent); border-left-color: var(--accent); background: rgba(232,160,32,.06); }

/* ---- Sidebar user card ---- */
.sidebar-user {
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}
.sidebar-user .avatar {
    width: 44px; height: 44px;
    border-radius: var(--radius);
    background: var(--accent2);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 16px; color: #000;
}
.sidebar-user .avatar.large { width: 48px; height: 48px; font-size: 18px; }
.sidebar-user-name { font-size: 14px; font-weight: 500; color: var(--text); }
.sidebar-user-role { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.sidebar-footer { margin-top: auto; padding: 8px 0; border-top: 1px solid var(--border); }

/* ---- Main content ---- */
.app-main {
    overflow-y: auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    min-height: 0;
    height: 100%;
    padding: 24px 28px;
}
.app-main > * + * {
    margin-top: 24px;
}

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-header {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    flex-wrap: wrap;
}
.page-header-left { flex: 1; min-width: 0; }
.page-title { font-size: 20px; font-weight: 600; color: var(--text); }
.page-sub   { font-size: 12px; color: var(--muted2); margin-top: 2px; font-family: var(--font-mono); }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ============================================================
   STAT CARDS
   ============================================================ */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: border-color .15s;
}
.stat-card:hover { border-color: var(--border2); }
.stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 600; }
.stat-value { font-family: var(--font-mono); font-size: 28px; font-weight: 500; color: var(--text); line-height: 1; }
.stat-value.amber { color: var(--accent); }
.stat-value.green { color: var(--green); }
.stat-value.red   { color: var(--red); }
.stat-sub { font-size: 11px; color: var(--muted2); }

/* ============================================================
   TABLES
   ============================================================ */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.table-header {
    display: flex;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}
.table-title { font-weight: 600; font-size: 13px; }
.table-header .ml-auto { margin-left: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead tr { border-bottom: 1px solid var(--border); }
th {
    text-align: left;
    padding: 10px 16px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--muted);
    white-space: nowrap;
}
td {
    padding: 11px 16px;
    border-bottom: 1px solid rgba(255,255,255,.04);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
.asset-code { font-family: var(--font-mono); font-size: 12px; color: var(--accent); }
.eq-name { font-weight: 500; }
.eq-type  { font-size: 11px; color: var(--muted2); }

/* ============================================================
   BADGES / STATUS PILLS
   ============================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 2px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .5px;
    text-transform: uppercase;
    white-space: nowrap;
}
.badge-green  { background: rgba(61,179,122,.15); color: #5cd49e; }
.badge-amber  { background: rgba(232,160,32,.15); color: var(--accent); }
.badge-red    { background: rgba(224,82,82,.15);  color: #f08080; }
.badge-blue   { background: rgba(74,159,212,.15); color: #79c0f0; }
.badge-gray   { background: rgba(255,255,255,.07); color: var(--muted2); }
.badge-orange { background: rgba(224,106,48,.15); color: #f0905a; }

/* Status → badge mapping helpers */
.status-in-service   { --c: var(--green); }
.status-in-shop      { --c: var(--blue); }
.status-out-of-service { --c: var(--red); }

/* ============================================================
   FORMS
   ============================================================ */
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .8px; color: var(--muted2); }
.form-control {
    background: var(--bg2);
    border: 1px solid var(--border2);
    color: var(--text);
    border-radius: var(--radius);
    padding: 9px 12px;
    font-size: 14px;
    font-family: var(--font-body);
    transition: border-color .15s;
    width: 100%;
}
.form-control:focus { outline: none; border-color: var(--accent); }
.form-control::placeholder { color: var(--muted); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-row { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
.form-row.thirds { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 640px) { .form-row, .form-row.thirds { grid-template-columns: 1fr; } }

.form-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.form-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--muted2);
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
    margin-bottom: 2px;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-body);
    cursor: pointer;
    border: 1px solid transparent;
    transition: all .15s;
    white-space: nowrap;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 14px; height: 14px; }
.btn-primary { background: var(--accent); color: #000; border-color: var(--accent); }
.btn-primary:hover { background: #f0b030; }
.btn-secondary { background: var(--surface2); color: var(--text); border-color: var(--border2); }
.btn-secondary:hover { border-color: var(--muted); }
.btn-danger { background: rgba(224,82,82,.15); color: var(--red); border-color: rgba(224,82,82,.3); }
.btn-danger:hover { background: rgba(224,82,82,.25); }
.btn-ghost { background: transparent; color: var(--muted2); }
.btn-ghost:hover { color: var(--text); background: var(--surface2); }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-icon { padding: 7px; width: 32px; height: 32px; }
.btn:disabled, .btn.loading { opacity: .55; pointer-events: none; }
.btn.loading::after {
    content: '';
    width: 12px; height: 12px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin .5s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    border-left: 3px solid;
    margin-bottom: 12px;
}
.alert-danger  { background: rgba(224,82,82,.1);   border-color: var(--red);   color: #f08080; }
.alert-success { background: rgba(61,179,122,.1);  border-color: var(--green); color: #6dd9a0; }
.alert-warning { background: rgba(232,160,32,.1);  border-color: var(--accent);color: var(--accent); }
.alert-info    { background: rgba(74,159,212,.1);  border-color: var(--blue);  color: #90d0f0; }

/* ============================================================
   TABS
   ============================================================ */
.tabs { display: flex; border-bottom: 1px solid var(--border); gap: 0; }
.tab {
    padding: 10px 18px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    color: var(--muted2);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color .15s, border-color .15s;
    white-space: nowrap;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab:hover:not(.active) { color: var(--text); }

/* ============================================================
   EQUIPMENT DETAIL CARD
   ============================================================ */
.equip-card {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px;
}
@media (max-width: 600px) { .equip-card { grid-template-columns: 1fr; } }
.equip-photo {
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: cover;
    border-radius: var(--radius);
    background: var(--surface2);
}
.equip-meta { display: flex; flex-direction: column; gap: 12px; }
.equip-meta-row { display: flex; flex-wrap: wrap; gap: 6px 20px; }
.meta-item { min-width: 120px; }
.meta-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }
.meta-value { font-size: 13px; color: var(--text); }
.meta-value.mono { font-family: var(--font-mono); }

/* ============================================================
   TIMELINE / LOG
   ============================================================ */
.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline-item {
    display: grid;
    grid-template-columns: 36px 1fr;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255,255,255,.04);
}
.timeline-item:last-child { border-bottom: none; }
.timeline-icon {
    width: 32px; height: 32px;
    border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.timeline-icon svg { width: 15px; height: 15px; }
.ti-insp  { background: rgba(74,159,212,.15);  color: var(--blue); }
.ti-repair{ background: rgba(224,82,82,.15);   color: var(--red); }
.ti-pm    { background: rgba(61,179,122,.15);  color: var(--green); }
.ti-comm  { background: rgba(255,255,255,.06); color: var(--muted2); }
.ti-down  { background: rgba(232,160,32,.15);  color: var(--accent); }

.timeline-content { flex: 1; min-width: 0; }
.timeline-title { font-weight: 500; font-size: 13px; color: var(--text); }
.timeline-meta  { font-size: 11px; color: var(--muted2); margin-top: 2px; }
.timeline-desc  { font-size: 12px; color: var(--muted2); margin-top: 4px; }

/* ============================================================
   QR code display area (for print)
   ============================================================ */
.qr-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px;
    background: #fff;
    border-radius: var(--radius);
    color: #000;
    width: fit-content;
}
.qr-wrap img { width: 140px; height: 140px; }
.qr-asset-code { font-family: var(--font-mono); font-size: 11px; font-weight: 500; }

/* ============================================================
   UTILITY
   ============================================================ */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.ml-auto { margin-left: auto; }
.text-muted { color: var(--muted2); font-size: 12px; }
.text-mono { font-family: var(--font-mono); }
.text-sm { font-size: 12px; }
.text-amber { color: var(--accent); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.w-full { width: 100%; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.p-0 { padding: 0; }
.hidden { display: none !important; }

/* Responsive split grid (used on dashboard) */
.responsive-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ---- Search bar ---- */
.search-bar {
    display: flex;
    align-items: center;
    background: var(--bg2);
    border: 1px solid var(--border2);
    border-radius: var(--radius);
    padding: 0 10px;
    gap: 6px;
    min-width: 220px;
}
.search-bar svg { color: var(--muted); width: 14px; height: 14px; flex-shrink: 0; }
.search-bar input {
    background: none;
    border: none;
    color: var(--text);
    font-size: 13px;
    padding: 7px 0;
    outline: none;
    width: 100%;
}
.search-bar input::placeholder { color: var(--muted); }

/* ============================================================
   MOBILE-SPECIFIC OVERRIDES (QR scan UX)
   ============================================================ */
@media (max-width: 768px) {
    .app-layout {
        grid-template-columns: 1fr;
        grid-template-rows: var(--top-h) 1fr;
    }
    .app-sidebar {
        position: fixed;
        top: var(--top-h);
        left: -100%;
        width: 280px;
        height: calc(100vh - var(--top-h));
        z-index: 200;
        transition: left .25s cubic-bezier(.16,1,.3,1);
        box-shadow: var(--shadow);
    }
    .app-sidebar.open { left: 0; }
    .app-sidebar .sidebar-user { padding: 16px; }
    .app-main {
        padding: 16px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .form-row { grid-template-columns: 1fr; }
    .equip-card { grid-template-columns: 1fr; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
    .responsive-split { grid-template-columns: 1fr !important; }

    /* Table horizontal scroll */
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table-wrap table { min-width: 540px; }

    /* Card-style table rows */
    .table-wrap.card-table { overflow-x: visible; }
    .table-wrap.card-table table,
    .table-wrap.card-table thead,
    .table-wrap.card-table tbody,
    .table-wrap.card-table tr,
    .table-wrap.card-table td,
    .table-wrap.card-table th { display: block; }
    .table-wrap.card-table thead { display: none; }
    .table-wrap.card-table tr {
        padding: 14px 16px;
        border-bottom: 1px solid var(--border);
        margin: 0;
    }
    .table-wrap.card-table td {
        border: none;
        padding: 3px 0;
        font-size: 13px;
        display: flex;
        align-items: center;
        gap: 6px;
    }
    .table-wrap.card-table td:empty { display: none; }

    /* Hide desktop search bar on mobile */
    .search-bar { display: none; }

    /* Big tap targets for mobile */
    .nav-link { padding: 12px 16px; min-height: 44px; }
    .nav-section-label { padding-top: 20px; padding-bottom: 6px; }
    .topbar-badge { width: 40px; height: 40px; }
    .user-chip { min-height: 40px; }
    .form-control { padding: 11px 14px; font-size: 16px; }
    .btn { min-height: 40px; }
    .btn-sm { min-height: 32px; }
    select.form-control { font-size: 16px; }
    .tab { padding: 12px 14px; }

    .mobile-action-btn {
        display: flex;
        align-items: center;
        gap: 12px;
        width: 100%;
        padding: 16px 18px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        color: var(--text);
        font-size: 15px;
        font-weight: 500;
        cursor: pointer;
        transition: background .15s, border-color .15s;
        text-align: left;
        -webkit-tap-highlight-color: transparent;
    }
    .mobile-action-btn:hover { background: var(--surface2); border-color: var(--border2); }
    .mobile-action-btn:active { background: var(--surface); transform: scale(.98); }
    .mobile-action-btn .mab-icon {
        width: 40px; height: 40px;
        border-radius: var(--radius);
        display: flex; align-items: center; justify-content: center;
        flex-shrink: 0;
    }

    /* Page actions stack on mobile */
    .page-actions { width: 100%; }
    .page-header { flex-direction: column; }
}

@media (max-width: 480px) {
    .stat-grid { grid-template-columns: 1fr; }
    .app-main { padding: 12px; }
    .form-section { padding: 16px; }
    .page-title { font-size: 18px; }
    .app-topbar { padding: 0 12px; gap: 6px; }
    .app-logo { font-size: 13px; }
}

/* ============================================================
   PRINT — QR label sheet
   ============================================================ */
@media print {
    body { background: #fff; color: #000; }
    .app-topbar, .app-sidebar { display: none; }
    .app-main { padding: 0; }
    .no-print { display: none !important; }
    .qr-label-sheet {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 8mm;
        padding: 8mm;
    }
    .qr-label {
        border: 1px solid #ccc;
        border-radius: 4px;
        padding: 6mm;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
        break-inside: avoid;
        font-family: 'IBM Plex Mono', monospace;
        font-size: 9pt;
    }
}
