/* =====================================================================
   WHS Maintenance Tracker — styling
   ===================================================================== */
:root {
    --bg:        #0f172a;
    --sidebar:   #111827;
    --panel:     #ffffff;
    --panel-2:   #f8fafc;
    --border:    #e2e8f0;
    --text:      #1e293b;
    --muted:     #64748b;
    --primary:   #2563eb;
    --primary-d: #1d4ed8;
    --green:     #16a34a;
    --red:       #dc2626;
    --amber:     #d97706;
    --purple:    #7c3aed;
    --radius:    12px;
    --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--panel-2);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

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

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

.sidebar {
    width: 240px;
    background: var(--sidebar);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand {
    display: flex; align-items: center; gap: 10px;
    padding: 20px 20px 12px;
    font-weight: 700;
}
.brand-mark {
    background: var(--primary); color: #fff;
    padding: 6px 10px; border-radius: 8px; font-size: 13px; letter-spacing: 1px;
}
.brand-text { color: #fff; font-size: 16px; }

.nav { display: flex; flex-direction: column; padding: 12px 12px; gap: 2px; flex: 1; }
.nav a {
    color: #cbd5e1; padding: 10px 14px; border-radius: 8px; font-weight: 500;
}
.nav a:hover { background: #1f2937; color: #fff; text-decoration: none; }
.nav a.active { background: var(--primary); color: #fff; }

.sidebar-foot { padding: 16px; border-top: 1px solid #1f2937; }
.user-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.user-name { color: #fff; font-size: 13px; font-weight: 600; }
.user-role { color: #94a3b8; font-size: 12px; }
.logout {
    display: block; text-align: center; padding: 8px; border-radius: 8px;
    background: #1f2937; color: #e2e8f0 !important; font-weight: 500;
}
.logout:hover { background: #374151; text-decoration: none; }

/* Language switcher */
.lang-switch { display: flex; gap: 6px; margin-bottom: 12px; }
.lang-switch a {
    flex: 1; text-align: center; padding: 6px 8px; border-radius: 8px;
    background: #1f2937; color: #cbd5e1 !important; font-weight: 600; font-size: 13px;
}
.lang-switch a:hover { background: #374151; text-decoration: none; }
.lang-switch a.active { background: var(--primary); color: #fff !important; }
.lang-switch-login {
    justify-content: flex-end; margin-bottom: 16px;
}
.lang-switch-login a {
    flex: 0 0 auto; background: var(--panel-2); color: var(--muted) !important;
    border: 1px solid var(--border); padding: 5px 12px;
}
.lang-switch-login a.active { background: var(--primary); color: #fff !important; border-color: var(--primary); }

/* Topbar (header) variant — light theme, aligned to the end */
.lang-switch-top { margin: 0 0 0 auto; }
[dir="rtl"] .lang-switch-top { margin: 0 auto 0 0; }
.lang-switch-top a {
    flex: 0 0 auto; background: var(--panel); color: var(--muted) !important;
    border: 1px solid var(--border); padding: 6px 12px; min-width: 38px;
}
.lang-switch-top a:hover { background: var(--panel-2); }
.lang-switch-top a.active { background: var(--primary); color: #fff !important; border-color: var(--primary); }

.content { flex: 1; padding: 0 32px 48px; max-width: 1200px; min-width: 0; }
.topbar {
    display: flex; align-items: center; gap: 12px;
    padding: 24px 0 8px; margin-bottom: 16px; border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 22px; margin: 0; }

/* Mobile hamburger + off-canvas overlay (hidden on desktop) */
.nav-toggle {
    display: none; background: var(--panel); border: 1px solid var(--border);
    color: var(--text); font-size: 20px; line-height: 1; border-radius: 8px;
    width: 40px; height: 40px; cursor: pointer; flex-shrink: 0;
}
.nav-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40;
}

/* ------------------------- Flash ------------------------- */
.flash { padding: 12px 16px; border-radius: 8px; margin: 16px 0; font-weight: 500; }
.flash-success { background: #dcfce7; color: #166534; }
.flash-error   { background: #fee2e2; color: #991b1b; }
.flash-info    { background: #dbeafe; color: #1e40af; }

/* ------------------------- Cards / grid ------------------------- */
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

.card {
    background: var(--panel); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.card h2, .card h3 { margin-top: 0; }

.stat { display: flex; flex-direction: column; gap: 4px; }
.stat .stat-num { font-size: 28px; font-weight: 700; }
.stat .stat-label { color: var(--muted); font-size: 13px; }
.stat .stat-accent { height: 4px; border-radius: 4px; margin-bottom: 10px; width: 40px; }

/* Compact / professional KPI cards */
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
@media (max-width: 900px) { .kpi-row { grid-template-columns: 1fr 1fr; } }
.kpi {
    background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
    padding: 14px 16px; box-shadow: var(--shadow);
    display: flex; align-items: center; gap: 12px;
}
.kpi .kpi-icon {
    width: 38px; height: 38px; border-radius: 9px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.kpi .kpi-num { font-size: 20px; font-weight: 700; line-height: 1.1; }
.kpi .kpi-label { color: var(--muted); font-size: 12px; margin-top: 1px; }
.kpi.kpi-primary .kpi-icon { background: #dbeafe; color: #1d4ed8; }
.kpi.kpi-red     .kpi-icon { background: #fee2e2; color: #b91c1c; }
.kpi.kpi-amber   .kpi-icon { background: #fef3c7; color: #b45309; }
.kpi.kpi-green   .kpi-icon { background: #dcfce7; color: #15803d; }

/* Dashboard page header with subtitle */
.page-intro { margin: 4px 0 20px; }
.page-intro .lead { color: var(--muted); font-size: 13px; }

.panel-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 15px; }
.panel-head .count-pill {
    background: var(--panel-2); color: var(--muted); border: 1px solid var(--border);
    border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600;
}
.empty-state { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty-state .es-icon { font-size: 30px; opacity: .5; }

/* Compact summary rows */
.mini-stats > div {
    display: flex; align-items: center; justify-content: space-between;
    padding: 5px 0; border-bottom: 1px dashed var(--border); font-size: 12.5px;
}
.mini-stats > div:last-child { border-bottom: 0; }
.mini-stats .ms-label { color: var(--muted); }
.mini-stats .ms-value { font-weight: 700; }

/* ------------------------- Tables ------------------------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 12px; border: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
tr:hover td { background: var(--panel-2); }
.table-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); -webkit-overflow-scrolling: touch; }
.table-wrap table { min-width: 560px; }

/* ------------------------- Badges ------------------------- */
.badge {
    display: inline-block; padding: 3px 10px; border-radius: 999px;
    font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-green  { background: #dcfce7; color: #166534; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-amber  { background: #fef3c7; color: #92400e; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-purple { background: #ede9fe; color: #5b21b6; }
.badge-gray   { background: #e2e8f0; color: #475569; }

/* ------------------------- Buttons ------------------------- */
.btn {
    display: inline-block; padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
    font-weight: 600; font-size: 14px; cursor: pointer; background: var(--primary); color: #fff;
}
.btn:hover { background: var(--primary-d); text-decoration: none; }
.btn-ghost { background: #fff; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--panel-2); }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: #b91c1c; }
.btn-success { background: var(--green); }
.btn-success:hover { background: #15803d; }
.btn-sm { padding: 5px 12px; font-size: 13px; }

/* ------------------------- Forms ------------------------- */
.form-row { margin-bottom: 16px; }
label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
input, select, textarea {
    width: 100%; padding: 10px 12px; border: 1px solid #94a3b8;
    border-radius: 8px; font-size: 14px; font-family: inherit; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
textarea { min-height: 90px; resize: vertical; }
.form-inline { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.form-inline .form-row { flex: 1; min-width: 140px; margin-bottom: 0; }

/* Password field with show/hide toggle */
.pwd-wrap { position: relative; }
.pwd-wrap input { padding-right: 62px; }
[dir="rtl"] .pwd-wrap input { padding-right: 12px; padding-left: 62px; }
.pwd-toggle {
    position: absolute; top: 50%; transform: translateY(-50%); right: 6px;
    background: transparent; border: 0; color: var(--primary); font-weight: 600;
    font-size: 12px; cursor: pointer; padding: 6px 8px; width: auto;
}
[dir="rtl"] .pwd-toggle { right: auto; left: 6px; }
.pwd-toggle:hover { text-decoration: underline; }

/* Table search box */
.table-search {
    width: 100%; max-width: 320px; padding: 9px 12px 9px 34px;
    border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E") no-repeat 10px center;
}
[dir="rtl"] .table-search { padding: 9px 34px 9px 12px; background-position: right 10px center; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin: 28px 0 14px; }
.section-head h2 { margin: 0; font-size: 18px; }

/* ------------------------- Progress tracker ------------------------- */
.tracker { display: flex; gap: 0; margin: 8px 0 4px; flex-wrap: wrap; }
.tracker .step {
    flex: 1; min-width: 120px; text-align: center; position: relative; padding-top: 28px;
    color: var(--muted); font-size: 12px; font-weight: 600;
}
.tracker .step::before {
    content: ""; position: absolute; top: 8px; left: 50%; width: 100%; height: 3px;
    background: var(--border); z-index: 0;
}
.tracker .step:last-child::before { display: none; }
.tracker .dot {
    position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    width: 18px; height: 18px; border-radius: 50%; background: #fff;
    border: 3px solid var(--border); z-index: 1;
}
.tracker .step.done { color: var(--green); }
.tracker .step.done .dot { background: var(--green); border-color: var(--green); }
.tracker .step.done::before { background: var(--green); }
.tracker .step.current { color: var(--primary); }
.tracker .step.current .dot { background: var(--primary); border-color: var(--primary); }

/* ------------------------- Timeline ------------------------- */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 18px 24px; border-left: 2px solid var(--border); }
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before {
    content: ""; position: absolute; left: -7px; top: 2px;
    width: 12px; height: 12px; border-radius: 50%; background: var(--primary);
}
.timeline .t-time { color: var(--muted); font-size: 12px; }
.timeline .t-title { font-weight: 600; }

/* ------------------------- Login ------------------------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg,#1e293b,#0f172a); }
.login-card { background: #fff; padding: 36px; border-radius: 16px; width: 360px; box-shadow: 0 20px 40px rgba(0,0,0,.3); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; text-align: center; }
.login-card .sub { text-align: center; color: var(--muted); margin-bottom: 24px; }
.login-card .btn { width: 100%; }
.login-hint { margin-top: 18px; font-size: 12px; color: var(--muted); text-align: center; }

.helper { color: var(--muted); font-size: 13px; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.right { text-align: right; }
.muted { color: var(--muted); }
.dl { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; }
.dl dt { color: var(--muted); font-weight: 600; }
.dl dd { margin: 0; }

/* ============================ RTL (Arabic) ============================ */
body.rtl { font-family: "Segoe UI", Tahoma, "Noto Naskh Arabic", Arial, sans-serif; }
[dir="rtl"] th, [dir="rtl"] td { text-align: right; }
[dir="rtl"] .right { text-align: left; }
[dir="rtl"] .timeline li { padding: 0 24px 18px 0; border-left: 0; border-right: 2px solid var(--border); }
[dir="rtl"] .timeline li:last-child { border-right-color: transparent; }
[dir="rtl"] .timeline li::before { left: auto; right: -7px; }
[dir="rtl"] .tracker .step::before { left: auto; right: 50%; }

/* ============================ Responsive ============================ */
@media (max-width: 1024px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 860px) {
    .content { padding: 0 16px 40px; }
    .topbar { padding: 16px 0 8px; }
    .topbar h1 { font-size: 18px; }

    /* Off-canvas sidebar */
    .nav-toggle { display: flex; align-items: center; justify-content: center; }
    .sidebar {
        position: fixed; top: 0; left: 0; height: 100vh; width: 250px; z-index: 50;
        transform: translateX(-100%); transition: transform .25s ease;
    }
    body.nav-open .sidebar { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.4); }
    body.nav-open .nav-overlay { display: block; }

    /* RTL: slide in from the right */
    [dir="rtl"] .sidebar { left: auto; right: 0; transform: translateX(100%); }
    [dir="rtl"] body.nav-open .sidebar { transform: translateX(0); }

    .brand-text, .user-name, .user-role, .nav a { font-size: inherit; }

    .kpi-row { grid-template-columns: 1fr 1fr; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .dl { grid-template-columns: 1fr; gap: 2px 0; }
    .dl dt { margin-top: 8px; }
    .section-head { flex-direction: column; align-items: flex-start; gap: 10px; }
    .form-inline { gap: 10px; }
}

@media (max-width: 520px) {
    .kpi-row { grid-template-columns: 1fr; }
    .panel-head { flex-direction: column; align-items: flex-start; gap: 10px; }
    .login-card { width: 100%; margin: 16px; padding: 28px 22px; }
    .btn { width: auto; }
}

/* Extra mobile usability */
@media (max-width: 768px) {
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table-wrap table { min-width: 640px; }
    .form-inline { flex-direction: column; align-items: stretch; }
    .form-inline .form-row { width: 100%; max-width: 100% !important; }
    .form-row label { margin-top: 4px; }
    .section-head, .panel-head { flex-wrap: wrap; }
    .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 520px) {
    .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .table-search { max-width: 100%; }
}

/* Inventory compact action panel */
.inventory-actions { margin-bottom: 12px; }
.inventory-actions .card { padding: 10px 12px; }
.inventory-actions h3 { font-size: 14px; margin: 0 0 8px; }
.inventory-actions .form-row { margin-bottom: 6px; }
.inventory-actions .form-inline { gap: 8px; align-items: flex-end; }
.inventory-actions input,
.inventory-actions select,
.inventory-actions .btn { padding: 5px 8px; font-size: 12px; }
.inventory-actions .btn { padding: 5px 12px; }

/* Compact professional tables for inventory */
#stockTable th, #stockTable td,
#historyTable th, #historyTable td {
    padding: 5px 8px;
    font-size: 13px;
    vertical-align: middle;
}
#stockTable th,
#historyTable th {
    background: var(--panel-2);
    color: var(--muted);
    font-weight: 600;
    font-size: 11px;
    letter-spacing: 0.03em;
}
#stockTable tbody tr:nth-child(even) td,
#historyTable tbody tr:nth-child(even) td {
    background: #f8fafc;
}
#stockTable .btn-sm,
#historyTable .btn-sm {
    padding: 3px 8px;
    font-size: 11px;
}
