/* ==============================================================
   AMIRNA ERP — Stylesheet
   Custom CSS, no framework dependency. Mobile-first.
   Design tokens are CSS variables so future theming is cheap.
   ============================================================== */

/* ---- Design tokens ------------------------------------------ */
:root {
    --bg-body:        #f7f8fb;
    --bg-surface:     #ffffff;
    --bg-muted:       #f1f3f7;
    --bg-sidebar:     #0f172a;
    --bg-sidebar-hv:  #1e293b;
    --bg-accent-soft: #eef2ff;

    --text-primary:   #0f172a;
    --text-secondary: #475569;
    --text-muted:     #64748b;
    --text-inverse:   #f8fafc;

    --border:         #e2e8f0;
    --border-strong:  #cbd5e1;
    --border-focus:   #6366f1;

    --accent:         #4f46e5;
    --accent-hover:   #4338ca;
    --accent-soft:    #e0e7ff;

    --danger:         #dc2626;
    --warning:        #d97706;
    --success:        #059669;

    --radius-sm:  6px;
    --radius:     10px;
    --radius-lg:  14px;

    --shadow-sm:  0 1px 2px rgba(15,23,42,.04);
    --shadow:     0 2px 8px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04);
    --shadow-lg:  0 12px 32px rgba(15,23,42,.08), 0 2px 6px rgba(15,23,42,.04);

    --sidebar-w:    248px;
    --sidebar-w-sm: 68px;
    --topbar-h:     60px;

    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

/* ---- Reset -------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-body);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
button { font: inherit; cursor: pointer; border: 0; background: transparent; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; display: block; }
table { border-collapse: collapse; }

/* ---- Auth screen (public, no sidebar) ----------------------- */
.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(1200px 600px at 10% -10%, #e0e7ff 0%, transparent 50%),
        radial-gradient(900px 500px at 90% 110%, #ddd6fe 0%, transparent 60%),
        var(--bg-body);
}
.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 32px;
}
.auth-card h1 {
    font-size: 22px;
    font-weight: 600;
    margin: 0 0 6px;
    letter-spacing: -0.01em;
}
.auth-card .subtitle {
    color: var(--text-muted);
    margin: 0 0 24px;
    font-size: 13.5px;
}
.auth-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 18px;
    margin-bottom: 24px;
    letter-spacing: -0.02em;
}
.auth-logo-mark {
    width: 32px; height: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, #4f46e5, #a855f7);
    display: grid; place-items: center;
    color: #fff;
    font-weight: 700;
    font-size: 14px;
}

/* ---- Forms -------------------------------------------------- */
.field { margin-bottom: 16px; }
.field label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.input, .select, .textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    font: inherit;
    color: var(--text-primary);
    transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(99,102,241,.18);
}
.textarea { min-height: 90px; resize: vertical; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); }

/* ---- Buttons ------------------------------------------------ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 13.5px;
    border: 1px solid transparent;
    white-space: nowrap;
    transition: background .12s, border-color .12s, transform .04s;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-hover); }
.btn--secondary {
    background: var(--bg-surface);
    border-color: var(--border-strong);
    color: var(--text-primary);
}
.btn--secondary:hover { background: var(--bg-muted); }
.btn--ghost { background: transparent; color: var(--text-secondary); }
.btn--ghost:hover { background: var(--bg-muted); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover { background: #b91c1c; }
.btn--sm { padding: 6px 10px; font-size: 12.5px; }
.btn--block { width: 100%; }

/* ---- Alerts ------------------------------------------------- */
.alert {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 13.5px;
    margin-bottom: 16px;
}
.alert--error { background: #fee2e2; border-color: #fecaca; color: #991b1b; }
.alert--success { background: #d1fae5; border-color: #a7f3d0; color: #065f46; }
.alert--warning { background: #fef3c7; border-color: #fde68a; color: #92400e; }
.alert--info { background: #dbeafe; border-color: #bfdbfe; color: #1e40af; }

/* ---- App layout --------------------------------------------- */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas:
        "sidebar topbar"
        "sidebar main";
    min-height: 100vh;
}
.sidebar {
    grid-area: sidebar;
    background: var(--bg-sidebar);
    color: var(--text-inverse);
    padding: 18px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px 18px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    margin-bottom: 14px;
}
.sidebar .brand .mark {
    width: 30px; height: 30px;
    border-radius: 8px;
    background: linear-gradient(135deg, #4f46e5, #a855f7);
    display: grid; place-items: center;
    color: #fff; font-weight: 700; font-size: 13px;
}
.sidebar .brand .name { font-weight: 600; letter-spacing: -0.01em; font-size: 15px; }
.sidebar .nav-section {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #94a3b8;
    margin: 16px 10px 6px;
}
.sidebar .nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    color: #cbd5e1;
    font-size: 13.5px;
    font-weight: 500;
    transition: background .1s, color .1s;
}
.sidebar .nav-link:hover { background: var(--bg-sidebar-hv); color: #fff; text-decoration: none; }
.sidebar .nav-link.active {
    background: rgba(99,102,241,.18);
    color: #fff;
    box-shadow: inset 2px 0 0 var(--accent);
}
.sidebar .nav-link .icon { width: 16px; height: 16px; display: inline-block; flex-shrink: 0; }

.topbar {
    grid-area: topbar;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar .search {
    flex: 1;
    max-width: 420px;
    margin-left: 8px;
}
.topbar .search input {
    width: 100%;
    padding: 7px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-muted);
    font-size: 13px;
}
.topbar .user-menu {
    display: flex; align-items: center; gap: 10px;
    font-size: 13px; color: var(--text-secondary);
}
.avatar {
    width: 30px; height: 30px; border-radius: 999px;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    color: #fff; display: grid; place-items: center;
    font-weight: 600; font-size: 12px;
}

.main {
    grid-area: main;
    padding: 24px;
    min-width: 0;
}
.main > .page-header {
    margin-bottom: 20px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header h1 {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin: 0;
}
.page-header .subtitle { color: var(--text-muted); font-size: 13.5px; margin-top: 4px; }
.page-header .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- Cards + KPI ------------------------------------------- */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.card-header h2, .card-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.005em;
}
.card-body { padding: 18px; }

.kpi-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    margin-bottom: 22px;
}
.kpi {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}
.kpi .kpi-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.kpi .kpi-value {
    font-size: 24px;
    font-weight: 600;
    margin-top: 4px;
    letter-spacing: -0.02em;
}
.kpi .kpi-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}

/* ---- Filter bar -------------------------------------------- */
.filter-bar {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 16px;
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    align-items: end;
}
.filter-bar .field { margin-bottom: 0; }
.filter-bar .actions { display: flex; gap: 8px; justify-self: end; grid-column: 1 / -1; }

/* ---- Tables ------------------------------------------------ */
.table-wrap {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    box-shadow: var(--shadow-sm);
}
.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
}
.table th, .table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    white-space: nowrap;
}
.table th {
    background: var(--bg-muted);
    font-weight: 600;
    font-size: 11.5px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    position: sticky;
    top: 0;
}
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafbff; }
.table td .sub {
    display: block;
    font-size: 11.5px;
    color: var(--text-muted);
    margin-top: 2px;
}
.table td.col-actions { text-align: right; }

.empty-state {
    padding: 48px 18px;
    text-align: center;
    color: var(--text-muted);
}
.empty-state h3 { color: var(--text-primary); font-size: 15px; margin: 8px 0 4px; }

/* ---- Pills ------------------------------------------------- */
.pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 500;
    line-height: 1.6;
    border: 1px solid transparent;
    white-space: nowrap;
}
.pill--slate   { background: #f1f5f9; color: #334155; border-color: #e2e8f0; }
.pill--indigo  { background: #eef2ff; color: #3730a3; border-color: #c7d2fe; }
.pill--sky     { background: #e0f2fe; color: #075985; border-color: #bae6fd; }
.pill--cyan    { background: #cffafe; color: #155e75; border-color: #a5f3fc; }
.pill--blue    { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.pill--emerald { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.pill--amber   { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.pill--rose    { background: #ffe4e6; color: #9f1239; border-color: #fecdd3; }
.pill--violet  { background: #ede9fe; color: #5b21b6; border-color: #ddd6fe; }
.pill--fuchsia { background: #fae8ff; color: #86198f; border-color: #f5d0fe; }
.pill--red     { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.pill--gray    { background: #f1f5f9; color: #334155; border-color: #e2e8f0; }

/* ---- Timeline ---------------------------------------------- */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li {
    position: relative;
    padding: 0 0 18px 24px;
    border-left: 2px solid var(--border);
    margin-left: 6px;
}
.timeline li::before {
    content: "";
    position: absolute;
    left: -6px; top: 2px;
    width: 10px; height: 10px;
    border-radius: 999px;
    background: var(--accent);
    box-shadow: 0 0 0 2px var(--bg-surface);
}
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline .ts { font-size: 11.5px; color: var(--text-muted); }
.timeline .evt { font-weight: 500; margin-top: 2px; }

/* ---- Comments ---------------------------------------------- */
.comment-feed { display: flex; flex-direction: column; gap: 10px; }
.comment {
    background: var(--bg-muted);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
}
.comment .meta {
    display: flex; justify-content: space-between;
    font-size: 11.5px;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.comment .body { white-space: pre-wrap; font-size: 13px; }

/* ---- Pagination -------------------------------------------- */
.pagination {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: center;
    padding: 14px;
    flex-wrap: wrap;
}
.pagination a, .pagination span {
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 13px;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}
.pagination a:hover { background: var(--bg-muted); text-decoration: none; }
.pagination .current {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.pagination .disabled { opacity: 0.5; pointer-events: none; }

/* ---- Utility classes --------------------------------------- */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.grid { display: grid; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12.5px; }
.text-xs { font-size: 11.5px; }
.mono { font-family: var(--font-mono); font-size: 12.5px; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }
.w-full { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none; }

/* ---- Modal skeleton ---------------------------------------- */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(15,23,42,0.45);
    display: grid; place-items: center;
    padding: 20px;
    z-index: 50;
}
.modal {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 520px;
    width: 100%;
    max-height: 90vh;
    overflow: auto;
}
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); font-weight: 600; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ---- Responsive -------------------------------------------- */
@media (max-width: 900px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-areas:
            "topbar"
            "main";
    }
    .sidebar {
        position: fixed;
        top: 0; left: 0;
        height: 100vh;
        width: var(--sidebar-w);
        transform: translateX(-100%);
        transition: transform .2s;
        z-index: 40;
    }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .topbar .hamburger {
        display: inline-flex;
        padding: 8px;
        margin-right: 6px;
        border-radius: 6px;
        color: var(--text-secondary);
    }
    .topbar .hamburger:hover { background: var(--bg-muted); }
}
@media (min-width: 901px) {
    .topbar .hamburger { display: none; }
}
@media (max-width: 600px) {
    .main { padding: 16px; }
    .topbar { padding: 0 16px; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .page-header h1 { font-size: 18px; }
}

/* ---- Mobile nav toggle (pure-CSS via checkbox trick) -------- */
#nav-toggle { display: none; }
#nav-toggle:checked ~ .app .sidebar { transform: translateX(0); }
