:root {
    --ht-navy: #12395b;
    --ht-navy-2: #0d2a43;
    --ht-blue: #1f6feb;
    --ht-teal: #1f8a8a;
    --ht-bg: #f3f6fa;
    --ht-border: #dfe6ee;
    --ht-text: #243447;
    --ht-muted: #6b7c93;
    --ht-sidebar: 252px;
    --ht-topbar: 68px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    background: var(--ht-bg);
    color: var(--ht-text);
    font-size: .93rem;
}

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

.app-shell { min-height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--ht-sidebar);
    background: linear-gradient(180deg, var(--ht-navy) 0%, var(--ht-navy-2) 100%);
    color: #dbe7f3;
    display: flex;
    flex-direction: column;
    z-index: 1030;
    transition: transform .2s ease;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: 1rem 1.1rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
    min-height: var(--ht-topbar);
}
.sidebar-brand img { height: 34px; width: auto; filter: brightness(0) invert(1); }
.sidebar-brand span { font-weight: 700; letter-spacing: .04em; font-size: .95rem; }

.sidebar-nav { padding: .8rem .6rem; overflow-y: auto; flex: 1; }
.sidebar-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    width: 100%;
    padding: .62rem .75rem;
    border: 0;
    border-radius: .5rem;
    background: transparent;
    color: #c8d8e8;
    font-size: .89rem;
    text-align: left;
    text-decoration: none;
    transition: background .15s ease, color .15s ease;
}
.sidebar-link i:first-child { width: 1.15rem; text-align: center; opacity: .9; }
.sidebar-link:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.sidebar-link.active { background: rgba(31,111,235,.9); color: #fff; box-shadow: 0 4px 12px rgba(0,0,0,.18); }
.sidebar-group { margin-bottom: .15rem; }
.sidebar-sublink {
    display: block;
    padding: .42rem .75rem .42rem 2.65rem;
    color: #a9bfd5;
    font-size: .85rem;
    border-radius: .4rem;
    text-decoration: none;
}
.sidebar-sublink:hover { color: #fff; background: rgba(255,255,255,.06); text-decoration: none; }
.sidebar-sublink.active { color: #fff; background: rgba(255,255,255,.13); font-weight: 600; }
.sidebar-footer { padding: .9rem 1.1rem; border-top: 1px solid rgba(255,255,255,.08); color: #8ea6bd; font-size: .72rem; }

/* ---------- main ---------- */
.app-main { margin-left: var(--ht-sidebar); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
    height: var(--ht-topbar);
    background: #fff;
    border-bottom: 1px solid var(--ht-border);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.4rem;
    position: sticky;
    top: 0;
    z-index: 1020;
}
.topbar-title { flex: 1; display: flex; align-items: baseline; gap: .8rem; }
.topbar-title h1 { font-size: 1.12rem; font-weight: 700; margin: 0; color: var(--ht-navy); }
.topbar-user { display: flex; align-items: center; gap: .5rem; }
.user-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: linear-gradient(135deg, var(--ht-navy), var(--ht-teal));
    color: #fff; display: grid; place-items: center;
    font-weight: 700; font-size: .8rem;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.15; }
.user-meta strong { font-size: .82rem; }
.user-meta small { color: var(--ht-muted); font-size: .72rem; }

.content { padding: 1.4rem; flex: 1; }
.app-footer {
    display: flex; justify-content: space-between;
    padding: .8rem 1.4rem; color: var(--ht-muted);
    font-size: .75rem; border-top: 1px solid var(--ht-border);
    background: #fff;
}

/* ---------- cards / tables ---------- */
.card { border: 1px solid var(--ht-border); border-radius: .65rem; box-shadow: 0 2px 10px rgba(18,57,91,.04); }
.card-header { background: #fff; border-bottom: 1px solid var(--ht-border); font-weight: 600; }
.card-body { padding: 1.1rem; }

.table { --bs-table-border-color: var(--ht-border); font-size: .86rem; }
.table thead th {
    background: #f8fafc; color: var(--ht-navy); font-size: .74rem;
    text-transform: uppercase; letter-spacing: .035em; white-space: nowrap;
    vertical-align: middle;
}
.table thead th a { color: inherit; text-decoration: none; }
.table thead th a:hover { color: var(--ht-blue); }
.table tbody tr:hover { background: #f8fbff; }
.table td, .table th { padding: .55rem .6rem; vertical-align: middle; }
.table .actions { white-space: nowrap; width: 1%; }
.table .actions a, .table .actions button { margin-right: .25rem; }
.table .actions i { font-size: .95rem; }
.table .actions a { color: var(--ht-navy); }
.table .actions a.text-danger { color: #c0392b !important; }

.badge-soft { padding: .3em .55em; border-radius: .35rem; font-weight: 600; font-size: .72rem; }
.badge-soft.secondary { background: #eef2f6; color: #5b6b7c; }
.badge-soft.success { background: #e4f6ec; color: #1c7c4a; }
.badge-soft.warning { background: #fff4d6; color: #9a6b00; }
.badge-soft.danger { background: #fde8e8; color: #b02a37; }
.badge-soft.info { background: #e7f1ff; color: #1f5fbf; }

.filters-bar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; }
.filters-bar .form-control, .filters-bar .form-select { min-width: 150px; }
.filters-bar .filter-actions { display: flex; gap: .4rem; }

.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.page-actions .spacer { flex: 1; }

.form-label { font-size: .8rem; font-weight: 600; color: #40566d; margin-bottom: .25rem; }
.form-control, .form-select { font-size: .88rem; border-color: #cfd9e4; }
.form-control:focus, .form-select:focus { border-color: var(--ht-blue); box-shadow: 0 0 0 .18rem rgba(31,111,235,.14); }
.required::after { content: " *"; color: #c0392b; }

.form-section { border-top: 1px solid var(--ht-border); margin-top: 1rem; padding-top: 1rem; }
.form-section-title { font-size: .78rem; font-weight: 700; text-transform: uppercase; color: var(--ht-muted); letter-spacing: .05em; margin-bottom: .7rem; }
.form-actions { display: flex; gap: .5rem; padding-top: 1rem; border-top: 1px solid var(--ht-border); margin-top: 1.2rem; }

/* ---------- auth ---------- */
.auth-body {
    min-height: 100vh;
    background:
        radial-gradient(1200px 600px at 10% 10%, rgba(31,111,235,.22), transparent 50%),
        radial-gradient(900px 500px at 90% 90%, rgba(31,138,138,.18), transparent 50%),
        linear-gradient(135deg, #0d2a43 0%, #12395b 55%, #0a2136 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}
.auth-wrap { width: 100%; max-width: 420px; }
.auth-card { background: #fff; border-radius: .8rem; padding: 2rem 2rem 1.6rem; box-shadow: 0 24px 70px rgba(0,0,0,.35); }
.auth-logo { text-align: center; margin-bottom: 1.2rem; }
.auth-logo img { max-height: 64px; }
.auth-title { font-size: 1.3rem; font-weight: 700; color: var(--ht-navy); margin-bottom: .2rem; }
.auth-copyright { text-align: center; color: rgba(255,255,255,.65); font-size: .75rem; margin-top: 1.2rem; }

/* ---------- calendar ---------- */
.calendar-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.calendar-panel { background: #fff; border: 1px solid var(--ht-border); border-radius: .65rem; padding: .75rem; }
.calendar-panel h3 { font-size: .85rem; font-weight: 700; color: var(--ht-navy); margin: .2rem 0 .6rem; }
.fc { font-size: .8rem; }
.fc .fc-toolbar-title { font-size: 1rem; }
.fc .fc-button { font-size: .75rem; padding: .3rem .55rem; }
.fc .fc-event { cursor: pointer; }

.task-modal .modal-body { max-height: 75vh; overflow-y: auto; }

/* ---------- misc ---------- */
.device-table td { padding: .35rem .4rem; }
.device-table input { min-width: 120px; }
.used-parts-list { list-style: none; padding: 0; margin: 0; }
.used-parts-list li { display: flex; align-items: center; gap: .5rem; padding: .3rem 0; border-bottom: 1px dashed var(--ht-border); }
.used-parts-row { display: flex; gap: .4rem; align-items: center; margin-bottom: .4rem; }
.used-parts-row input { max-width: 260px; }
.history-table { font-size: .8rem; }
.history-table tr[data-href] { cursor: pointer; }
.history-table tr[data-href]:hover { background: #eef6ff; }
.text-pre { white-space: pre-wrap; }
.stat-box { background: #fff; border: 1px solid var(--ht-border); border-radius: .6rem; padding: .8rem 1rem; }
.stat-box .value { font-size: 1.3rem; font-weight: 700; color: var(--ht-navy); }
.stat-box .label { font-size: .72rem; text-transform: uppercase; color: var(--ht-muted); letter-spacing: .04em; }

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .app-main { margin-left: 0; }
}

@media print {
    .sidebar, .topbar, .app-footer, .page-actions, .filters-bar, .no-print { display: none !important; }
    .app-main { margin-left: 0; }
    .content { padding: 0; }
    .card { box-shadow: none; border: 0; }
    body { background: #fff; font-size: 10pt; }
    .table { font-size: 9pt; }
}
