/* =====================================================================
   Admin UI — VISION Invoice System (sidebar layout, self-contained)
   ===================================================================== */

:root {
    --brand: #1f6fb2;
    --brand-dark: #155080;
    --green: #2e9e5b;
    --red: #d23b3b;
    --amber: #e0a100;
    --ink: #1f2937;
    --muted: #6b7280;
    --line: #e3e7ee;
    --bg: #f4f6f9;
    --card: #ffffff;
    --side: #14233a;
    --side-2: #1b2f4d;
    --side-text: #c7d2e0;
    --sidebar-w: 236px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===================== app shell ===================== */
body.app { min-height: 100vh; }

.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: linear-gradient(180deg, var(--side), var(--side-2));
    color: var(--side-text);
    display: flex;
    flex-direction: column;
    z-index: 20;
}
.side-logo {
    background: #fff;
    margin: 14px;
    border-radius: 10px;
    padding: 14px 12px;
    text-align: center;
}
.side-logo img { max-width: 100%; max-height: 46px; height: auto; }
.side-nav { display: flex; flex-direction: column; padding: 8px; gap: 2px; }
.side-nav a {
    display: flex; align-items: center; gap: 11px;
    color: var(--side-text);
    padding: 11px 13px;
    border-radius: 8px;
    font-weight: 500;
    font-size: 14.5px;
}
.side-nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; text-decoration: none; }
.side-nav a.active { background: var(--brand); color: #fff; }
.side-nav .ic { width: 20px; text-align: center; font-size: 15px; }
.side-foot { margin-top: auto; padding: 14px; color: #59708f; font-size: 12px; }

.main {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky; top: 0; z-index: 15;
    background: #fff;
    border-bottom: 1px solid var(--line);
    height: 60px;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.top-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* hamburger (mobile only) + drawer backdrop */
.nav-toggle {
    display: none;
    background: none; border: none; cursor: pointer;
    font-size: 22px; line-height: 1; color: var(--ink);
    padding: 6px 8px; border-radius: 8px;
}
.nav-toggle:hover { background: var(--bg); }
.sidebar-overlay {
    position: fixed; inset: 0; z-index: 19;
    background: rgba(17, 24, 39, .45); display: none;
}
.top-title { font-size: 18px; font-weight: 700; margin: 0; }

/* user menu */
.user-menu { position: relative; }
.user-btn {
    display: flex; align-items: center; gap: 10px;
    background: transparent; border: 1px solid transparent; cursor: pointer;
    padding: 6px 8px; border-radius: 8px; font-family: inherit;
}
.user-btn:hover { background: var(--bg); }
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--brand); color: #fff; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.15; text-align: left; }
.u-name { font-weight: 600; font-size: 13.5px; }
.u-role { color: var(--muted); font-size: 12px; }
.caret { color: var(--muted); }
.dropdown {
    position: absolute; right: 0; top: 52px;
    background: #fff; border: 1px solid var(--line); border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
    min-width: 190px; padding: 6px; display: none;
}
.dropdown.open { display: block; }
.dropdown a { display: block; padding: 9px 12px; border-radius: 7px; color: var(--ink); font-size: 13.5px; }
.dropdown a:hover { background: var(--bg); text-decoration: none; }
.dropdown a.danger { color: var(--red); }
.drop-sep { height: 1px; background: var(--line); margin: 5px 4px; }

.content { padding: 24px; max-width: 1180px; width: 100%; }
.app-foot { margin-top: auto; text-align: center; color: #9aa3b2; font-size: 12px; padding: 22px 0 26px; }

/* ===================== login ===================== */
.login-page {
    min-height: 100vh; margin: 0;
    background: linear-gradient(135deg, #16263a, #1f6fb2);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.login-card {
    background: #fff; width: 370px; max-width: 92vw;
    border-radius: 14px; padding: 30px 30px 34px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, .3);
}
.login-logo { text-align: center; margin-bottom: 14px; }
.login-logo img { max-height: 56px; max-width: 80%; height: auto; }
.login-card h1 { text-align: center; font-size: 22px; margin: 6px 0 2px; }
.login-sub { text-align: center; color: var(--muted); margin: 0 0 22px; font-size: 13.5px; }
.login-foot { color: #dbe6f2; font-size: 12px; margin-top: 18px; opacity: .85; }

/* ===================== headings ===================== */
.page-title { font-size: 22px; font-weight: 700; margin: 0 0 4px; }
.page-sub { color: var(--muted); margin: 0 0 20px; }

/* ===================== cards / stats ===================== */
.card {
    background: var(--card); border: 1px solid var(--line); border-radius: 10px;
    padding: 20px; margin-bottom: 18px; box-shadow: 0 1px 2px rgba(0, 0, 0, .03);
}
.card h3 { margin: 0 0 14px; font-size: 16px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: 10px; padding: 16px 18px; }
.stat .num { font-size: 26px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 13px; margin-top: 2px; }
.stat.green { border-left-color: var(--green); }
.stat.amber { border-left-color: var(--amber); }
.stat.red { border-left-color: var(--red); }

/* ===================== buttons ===================== */
.btn { display: inline-block; background: var(--brand); color: #fff; border: none; border-radius: 7px;
    padding: 9px 16px; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn.green { background: var(--green); } .btn.green:hover { background: #247a46; }
.btn.gray { background: #e7ebf1; color: var(--ink); } .btn.gray:hover { background: #d8dde6; }
.btn.red { background: var(--red); } .btn.red:hover { background: #b32f2f; }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 6px; }
.btn.outline { background: #fff; border: 1px solid var(--brand); color: var(--brand); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ===================== forms ===================== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 4px; }
.field.full { grid-column: 1 / -1; }
.field label { font-weight: 600; font-size: 13px; }
.field .hint { color: var(--muted); font-size: 12px; }
input[type=text], input[type=number], input[type=date], input[type=email],
input[type=password], select, textarea {
    padding: 9px 11px; border: 1px solid #cdd4df; border-radius: 7px;
    font-size: 14px; font-family: inherit; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: 18px; height: 18px; }

/* ===================== tables ===================== */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
table.data th { background: #f7f9fc; font-weight: 700; color: #374151; white-space: nowrap; }
table.data tr:hover td { background: #fafbfe; }
table.data td.num, table.data th.num { text-align: right; }
table.data td.center, table.data th.center { text-align: center; }

/* ===================== badges ===================== */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.vat { background: #e7f0fb; color: var(--brand-dark); }
.badge.novat { background: #eef1f5; color: #555; }
.badge.active { background: #e6f6ec; color: #1f7a42; }
.badge.inactive { background: #fdeaea; color: #a32a2a; }
.badge.role { background: #efe9fb; color: #5b3da8; }

/* ===================== flash / pagination / toolbar ===================== */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 18px; font-weight: 500; }
.flash.success { background: #e6f6ec; color: #1f7a42; border: 1px solid #b8e3c6; }
.flash.error { background: #fdeaea; color: #a32a2a; border: 1px solid #f1c0c0; }
.flash.info { background: #e7f0fb; color: var(--brand-dark); border: 1px solid #c3ddf4; }

/* ---- toast notifications ---- */
.toast-wrap { position: fixed; top: 72px; right: 22px; z-index: 1000; display: flex; flex-direction: column; gap: 10px; }
.toast {
    display: flex; align-items: center; gap: 12px;
    min-width: 260px; max-width: 380px;
    padding: 13px 14px 13px 16px; border-radius: 10px;
    background: #fff; color: var(--ink);
    box-shadow: 0 8px 28px rgba(0, 0, 0, .18);
    border-left: 5px solid var(--brand);
    font-weight: 500;
    animation: toastIn .3s ease;
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.info { border-left-color: var(--brand); }
.toast .toast-msg { flex: 1; font-size: 13.5px; }
.toast .toast-x { background: none; border: none; cursor: pointer; font-size: 20px; line-height: 1; color: #9aa3b2; padding: 0 2px; }
.toast .toast-x:hover { color: var(--ink); }
@keyframes toastIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: translateX(0); } }

/* ---- confirm modal ---- */
.modal-overlay {
    position: fixed; inset: 0; z-index: 2000;
    background: rgba(17, 24, 39, .55);
    display: none; align-items: center; justify-content: center;
    padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
    background: #fff; border-radius: 14px;
    width: 390px; max-width: 92vw;
    padding: 26px 26px 22px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, .4);
    text-align: center;
    animation: modalIn .2s ease;
}
.modal-icon {
    width: 58px; height: 58px; border-radius: 50%;
    background: #fdeaea; color: var(--red);
    font-size: 26px; display: flex; align-items: center; justify-content: center;
    margin: 0 auto 14px;
}
.modal-title { margin: 0 0 8px; font-size: 18px; font-weight: 700; }
.modal-msg { margin: 0 0 22px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }
.modal-actions .btn { min-width: 96px; }
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }

.pagination { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.pagination a, .pagination span { padding: 6px 11px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); }
.pagination .current { background: var(--brand); color: #fff; border-color: var(--brand); }
.pagination .disabled { color: #bbb; }

.toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar form { display: flex; gap: 8px; }
.toolbar input[type=text], .toolbar select { min-width: 200px; width: auto; }

/* AJAX results dim while loading */
#clientResults.loading { opacity: .45; pointer-events: none; transition: opacity .12s; }

.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt0 { margin-top: 0; }

/* ===================== responsive ===================== */

/* Laptop / small desktop: 4 stat tiles get tight -> 2 per row */
@media (max-width: 1024px) {
    .stats { grid-template-columns: repeat(2, 1fr); }
    .content { padding: 22px 18px; }
}

/* Tablet & mobile: sidebar becomes a slide-in drawer with a hamburger */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform .25s ease;
        box-shadow: 0 0 30px rgba(0, 0, 0, .35);
        z-index: 30;
    }
    body.app.nav-open .sidebar { transform: translateX(0); }
    body.app.nav-open .sidebar-overlay { display: block; }
    .main { margin-left: 0; }
    .nav-toggle { display: inline-flex; }
    .form-grid { grid-template-columns: 1fr; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar form { flex-wrap: wrap; }
    .toolbar input[type=text], .toolbar select { min-width: 0; flex: 1 1 160px; width: auto; }
    .content { padding: 18px 14px; }
}

/* Phones */
@media (max-width: 560px) {
    .stats { grid-template-columns: 1fr; }
    .topbar { padding: 0 12px; }
    .user-meta { display: none; }              /* keep avatar, drop name/role text */
    .page-title { font-size: 19px; }
    .card { padding: 16px 14px; }
    .btn-row { width: 100%; }
    .dropdown { right: 0; }
    table.data th, table.data td { padding: 9px 10px; }
}
