/* ============================================================
   HK Electronics — App Design System
   Clean business dashboard · responsive · print-ready
   ============================================================ */

:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-soft: #eef2ff;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-active: #312e81;
    --bg: #f1f5f9;
    --card: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-soft: #475569;
    --text-muted: #94a3b8;
    --green: #059669; --green-soft: #d1fae5;
    --red: #dc2626;   --red-soft: #fee2e2;
    --amber: #d97706; --amber-soft: #fef3c7;
    --blue: #2563eb;  --blue-soft: #dbeafe;
    --purple: #7c3aed; --purple-soft: #ede9fe;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
    --shadow-lg: 0 10px 30px rgba(15, 23, 42, .12);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14.5px;
    line-height: 1.55;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 12px; font-weight: 700; }
img { max-width: 100%; }

/* ---------------- Sidebar ---------------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px; flex-shrink: 0;
    background: var(--sidebar-bg); color: #cbd5e1;
    position: fixed; inset: 0 auto 0 0; z-index: 60;
    display: flex; flex-direction: column;
    transition: transform .25s ease;
    overflow-y: auto;
}
.sidebar .brand {
    display: flex; align-items: center; gap: 10px;
    padding: 18px 18px 14px; color: #fff; text-decoration: none;
}
.sidebar .brand:hover { text-decoration: none; }
.brand-logo {
    width: 38px; height: 38px; border-radius: 9px; flex-shrink: 0;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 800; font-size: 15px;
}
.brand-name { font-weight: 700; font-size: 16px; line-height: 1.2; }
.brand-sub { font-size: 11px; color: #64748b; }

.nav-groups { padding: 6px 10px 30px; flex: 1; }
.nav-group-title {
    font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em;
    color: #64748b; padding: 14px 10px 5px; font-weight: 700;
}
.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 8.5px 12px; border-radius: 8px; margin: 1px 0;
    color: #cbd5e1; text-decoration: none; font-size: 13.8px;
}
.nav-link:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.nav-link .ico { width: 19px; text-align: center; opacity: .85; flex-shrink: 0; }
.nav-link .cnt {
    margin-left: auto; background: var(--red); color: #fff; border-radius: 99px;
    font-size: 10.5px; padding: 1px 7px; font-weight: 700;
}

.sidebar-footer { padding: 12px 16px; border-top: 1px solid #1e293b; font-size: 11.5px; color: #64748b; }

/* ---------------- Main area ---------------- */
.main { flex: 1; margin-left: 250px; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    position: sticky; top: 0; z-index: 50;
    background: var(--card); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 14px;
    padding: 10px 22px; min-height: 58px;
}
.hamburger {
    display: none; border: 1px solid var(--border); background: #fff; border-radius: 8px;
    padding: 7px 11px; cursor: pointer; font-size: 16px; line-height: 1;
}
.global-search { flex: 1; max-width: 460px; position: relative; }
.global-search input {
    width: 100%; padding: 9px 14px 9px 38px; border: 1px solid var(--border);
    border-radius: 9px; background: var(--bg); font-size: 13.5px; outline: none;
}
.global-search input:focus { border-color: var(--primary); background: #fff; }
.global-search .s-ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }

.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.icon-btn {
    position: relative; border: 1px solid var(--border); background: #fff;
    width: 38px; height: 38px; border-radius: 9px; cursor: pointer; font-size: 16px;
    display: inline-flex; align-items: center; justify-content: center; color: var(--text-soft);
    text-decoration: none;
}
.icon-btn:hover { background: var(--bg); text-decoration: none; }
.icon-btn .dot {
    position: absolute; top: -5px; right: -5px; background: var(--red); color: #fff;
    font-size: 10px; font-weight: 700; min-width: 17px; height: 17px; border-radius: 99px;
    display: flex; align-items: center; justify-content: center; padding: 0 4px;
}
.user-chip {
    display: flex; align-items: center; gap: 10px; padding: 5px 6px 5px 12px;
    border: 1px solid var(--border); border-radius: 10px; background: #fff; position: relative;
}
.user-chip .u-name { font-size: 13px; font-weight: 600; line-height: 1.2; }
.user-chip .u-role { font-size: 11px; color: var(--text-muted); }
.avatar {
    width: 30px; height: 30px; border-radius: 99px; background: var(--primary-soft);
    color: var(--primary); font-weight: 700; font-size: 13px;
    display: flex; align-items: center; justify-content: center;
}
.dropdown { position: relative; }
.dropdown-menu {
    position: absolute; right: 0; top: calc(100% + 8px); min-width: 180px;
    background: #fff; border: 1px solid var(--border); border-radius: 10px;
    box-shadow: var(--shadow-lg); padding: 6px; display: none; z-index: 70;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a, .dropdown-menu button {
    display: block; width: 100%; text-align: left; padding: 8px 12px; border-radius: 7px;
    color: var(--text); font-size: 13.5px; background: none; border: 0; cursor: pointer;
}
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--bg); text-decoration: none; }

.content { padding: 22px; max-width: 1400px; width: 100%; margin: 0 auto; flex: 1; }

.breadcrumb { font-size: 12.5px; color: var(--text-muted); margin-bottom: 6px; }
.breadcrumb a { color: var(--text-soft); }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 21px; margin: 0; }
.page-head .spacer { flex: 1; }

/* ---------------- Cards ---------------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 18px; }
.card-h {
    padding: 14px 18px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.card-h h2, .card-h h3 { margin: 0; font-size: 15.5px; }
.card-b { padding: 18px; }
.card-b.p0 { padding: 0; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px 18px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.stat::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--primary); opacity: .85; }
.stat.green::before { background: var(--green); }
.stat.red::before { background: var(--red); }
.stat.amber::before { background: var(--amber); }
.stat.blue::before { background: var(--blue); }
.stat.purple::before { background: var(--purple); }
.stat .s-label { font-size: 12.5px; color: var(--text-soft); font-weight: 600; }
.stat .s-value { font-size: 23px; font-weight: 800; margin-top: 3px; letter-spacing: -.02em; }
.stat .s-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
    text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--text-muted); font-weight: 700; padding: 10px 14px;
    border-bottom: 1px solid var(--border); background: #f8fafc; white-space: nowrap;
}
.tbl td { padding: 10px 14px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.tbl tbody tr:hover { background: #f8fafc; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .actions { white-space: nowrap; text-align: right; }
.tbl .actions a, .tbl .actions button { margin-left: 6px; }

/* ---------------- Badges ---------------- */
.badge {
    display: inline-block; padding: 3px 10px; border-radius: 99px;
    font-size: 11.5px; font-weight: 700; white-space: nowrap; line-height: 1.5;
}
.badge-green { background: var(--green-soft); color: #065f46; }
.badge-red { background: var(--red-soft); color: #991b1b; }
.badge-amber { background: var(--amber-soft); color: #92400e; }
.badge-blue { background: var(--blue-soft); color: #1e40af; }
.badge-purple { background: var(--purple-soft); color: #5b21b6; }
.badge-gray { background: #f1f5f9; color: #475569; }

/* ---------------- Buttons ---------------- */
.btn {
    display: inline-flex; align-items: center; gap: 7px;
    background: var(--primary); color: #fff; border: 1px solid var(--primary);
    padding: 9px 16px; border-radius: 8px; font-size: 13.5px; font-weight: 600;
    cursor: pointer; text-decoration: none; transition: background .15s;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; color: #fff; }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--red); border-color: var(--red); }
.btn-danger:hover { background: #b91c1c; }
.btn-success { background: var(--green); border-color: var(--green); }
.btn-success:hover { background: #047857; }
.btn-sm { padding: 5px 11px; font-size: 12.5px; border-radius: 7px; }
.btn-ghost-danger { background: #fff; color: var(--red); border: 1px solid #fecaca; }
.btn-ghost-danger:hover { background: var(--red-soft); color: var(--red); }

/* ---------------- Forms ---------------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .cols-3 { grid-column: span 2; display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 18px; }
label.f { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-soft); margin-bottom: 5px; }
label.f .req { color: var(--red); }
.input, select.input, textarea.input {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
    font-size: 13.5px; font-family: inherit; background: #fff; color: var(--text); outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, .12); }
textarea.input { resize: vertical; min-height: 80px; }
.input-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13.5px; padding: 4px 0; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

/* ---------------- Filters ---------------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.filters .f-group { min-width: 150px; }
.filters label.f { margin-bottom: 4px; font-size: 11.5px; }

/* ---------------- Alerts / toasts ---------------- */
.alerts { position: fixed; top: 14px; right: 14px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: 380px; }
.alert {
    padding: 12px 16px; border-radius: 9px; font-size: 13.5px; font-weight: 500;
    box-shadow: var(--shadow-lg); animation: slideIn .25s ease; display: flex; gap: 8px;
}
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.alert-success { background: #ecfdf5; border: 1px solid #6ee7b7; color: #065f46; }
.alert-error { background: #fef2f2; border: 1px solid #fca5a5; color: #991b1b; }
.alert-info { background: #eff6ff; border: 1px solid #93c5fd; color: #1e40af; }
.alert-warning { background: #fffbeb; border: 1px solid #fcd34d; color: #92400e; }

/* ---------------- Modal ---------------- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(15, 23, 42, .55); z-index: 90;
    display: none; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; box-shadow: var(--shadow-lg); animation: pop .18s ease; }
.modal.lg { max-width: 800px; }
@keyframes pop { from { transform: scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-h { padding: 15px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal-h h3 { margin: 0; font-size: 16px; flex: 1; }
.modal-x { border: 0; background: none; font-size: 20px; cursor: pointer; color: var(--text-muted); line-height: 1; }
.modal-b { padding: 20px; }
.modal-f { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------------- Tabs ---------------- */
.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--border); flex-wrap: wrap; }
.tab {
    padding: 9px 16px; font-size: 13.5px; font-weight: 600; color: var(--text-soft);
    border: 0; background: none; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-pane { display: none; padding-top: 18px; }
.tab-pane.active { display: block; }

/* ---------------- Timeline ---------------- */
.timeline { position: relative; padding-left: 26px; }
.timeline::before { content: ''; position: absolute; left: 8px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.tl-item { position: relative; padding-bottom: 18px; }
.tl-item::before {
    content: ''; position: absolute; left: -24px; top: 4px; width: 12px; height: 12px;
    border-radius: 99px; background: var(--primary); border: 2.5px solid #fff; box-shadow: 0 0 0 1.5px var(--primary);
}
.tl-item.tl-gray::before { background: #94a3b8; box-shadow: 0 0 0 1.5px #94a3b8; }
.tl-item.tl-green::before { background: var(--green); box-shadow: 0 0 0 1.5px var(--green); }
.tl-item.tl-red::before { background: var(--red); box-shadow: 0 0 0 1.5px var(--red); }
.tl-time { font-size: 11.5px; color: var(--text-muted); }
.tl-title { font-weight: 600; font-size: 13.5px; }
.tl-detail { font-size: 13px; color: var(--text-soft); }

/* ---------------- Files / attachments ---------------- */
.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.file-card { border: 1px solid var(--border); border-radius: 9px; overflow: hidden; background: #fff; }
.file-card img { width: 100%; height: 100px; object-fit: cover; display: block; }
.file-card .pdf-thumb {
    height: 100px; display: flex; align-items: center; justify-content: center;
    background: var(--red-soft); color: var(--red); font-size: 26px; font-weight: 800;
}
.file-card .f-name { font-size: 11.5px; padding: 7px 9px 2px; word-break: break-all; }
.file-card .f-meta { font-size: 10.5px; color: var(--text-muted); padding: 0 9px 8px; display: flex; justify-content: space-between; }

.dropzone {
    border: 2px dashed var(--border); border-radius: 10px; padding: 22px; text-align: center;
    color: var(--text-muted); cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }

/* ---------------- Kanban board ---------------- */
.board { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 10px; align-items: flex-start; }
.board-col { background: #eef2f7; border-radius: 10px; padding: 10px; min-width: 250px; width: 250px; flex-shrink: 0; }
.board-col h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-soft); margin: 2px 4px 10px; }
.board-card { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; box-shadow: var(--shadow); }
.board-card .bc-title { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.board-card .bc-meta { font-size: 11.5px; color: var(--text-muted); display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------- Pagination ---------------- */
.pager { display: flex; gap: 6px; align-items: center; padding: 14px 18px; font-size: 13px; }
.pager a, .pager span.cur {
    padding: 6px 12px; border: 1px solid var(--border); border-radius: 7px; background: #fff; color: var(--text-soft);
}
.pager span.cur { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 700; }
.pager a:hover { background: var(--bg); text-decoration: none; }
.pager .p-info { margin-right: auto; color: var(--text-muted); }

/* ---------------- Auth pages ---------------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 55%, #312e81 100%); }
.auth-card { background: #fff; border-radius: 16px; padding: 34px; width: 100%; max-width: 420px; box-shadow: var(--shadow-lg); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth-brand .brand-logo { width: 46px; height: 46px; font-size: 18px; }
.auth-brand h1 { font-size: 20px; margin: 0; }
.auth-brand .sub { font-size: 12.5px; color: var(--text-muted); }
.auth-foot { text-align: center; font-size: 12.5px; color: var(--text-muted); margin-top: 18px; }
.demo-box { background: #f8fafc; border: 1px dashed var(--border); border-radius: 9px; padding: 10px 14px; font-size: 12px; color: var(--text-soft); margin-top: 16px; }

/* ---------------- Empty state ---------------- */
.empty { text-align: center; padding: 46px 20px; color: var(--text-muted); }
.empty .e-ico { font-size: 34px; margin-bottom: 8px; }
.empty .e-title { font-weight: 700; color: var(--text-soft); font-size: 15px; }
.empty .e-sub { font-size: 13px; }

/* ---------------- Detail rows ---------------- */
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 7px 14px; font-size: 13.5px; }
.kv .k { color: var(--text-muted); font-weight: 600; font-size: 12.5px; }

/* ---------------- Invoice print ---------------- */
.print-area { background: #fff; padding: 34px; max-width: 860px; margin: 0 auto; border: 1px solid var(--border); border-radius: 8px; }
.print-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 3px solid var(--primary); padding-bottom: 16px; margin-bottom: 20px; }
.print-head .co-name { font-size: 22px; font-weight: 800; color: var(--primary); }
.print-head .co-meta { font-size: 12.5px; color: var(--text-soft); line-height: 1.6; }
.print-inv-no { font-size: 19px; font-weight: 800; }
.badge-print { border: 2px solid var(--green); color: var(--green); padding: 4px 14px; border-radius: 6px; font-weight: 800; text-transform: uppercase; font-size: 12px; letter-spacing: .06em; }
.print-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 30px; margin-bottom: 18px; font-size: 13px; }
.print-total-row td { font-weight: 800; font-size: 14px; background: var(--primary-soft); }
.print-sign { display: flex; justify-content: space-between; margin-top: 60px; font-size: 13px; }
.print-sign div { border-top: 1px solid var(--text); padding-top: 6px; width: 200px; text-align: center; }

/* ---------------- Responsive ---------------- */
@media (max-width: 1024px) {
    .grid-2, .grid-3, .grid-2-1 { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .cols-3 { grid-template-columns: 1fr; grid-column: auto; }
    .kv { grid-template-columns: 1fr; }
    .kv .k { margin-top: 4px; }
}
@media (max-width: 860px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
    .main { margin-left: 0; }
    .hamburger { display: inline-block; }
    .content { padding: 14px; }
    .global-search { max-width: none; }
    .user-chip .u-meta { display: none; }
    .print-head { flex-direction: column; }
    .print-grid { grid-template-columns: 1fr; }
}

/* ---------------- Print ---------------- */
@media print {
    body { background: #fff; }
    .sidebar, .topbar, .alerts, .no-print, .modal-overlay { display: none !important; }
    .main { margin: 0; }
    .content { padding: 0; }
    .print-area { border: 0; border-radius: 0; padding: 10px; }
}
