/* =====================================================================
   Glen Test and Tag Services - Portal Stylesheet
   Palette sampled from the real company logo: deep navy, medium blue, red.
   ===================================================================== */

:root {
    --brand-primary: #1B4F72;
    --brand-primary-dark: #0F2A47;
    --brand-accent: #D72428;
    --brand-success: #1E8E5A;
    --brand-danger: #D72428;
    --brand-warning: #E8A419;
    --brand-info: #2C7BE5;
    --bg-light: #F4F7F8;
    --sidebar-width: 250px;
    --header-height: 64px;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-light);
    color: #1c2b30;
    font-size: 15px;
}

a { text-decoration: none; color: inherit; }

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

.sidebar {
    width: var(--sidebar-width);
    background: var(--brand-primary-dark);
    color: #fff;
    flex-shrink: 0;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform 0.25s ease;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.12);
}
.sidebar-logo img { height: 44px; width: auto; }
.sidebar-logo .company-name { font-weight: 700; font-size: 14.5px; line-height: 1.2; }
.sidebar-logo .company-tag { font-size: 11px; opacity: 0.75; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 0; }
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 20px;
    color: rgba(255,255,255,0.85);
    font-size: 14px;
    font-weight: 500;
    border-left: 3px solid transparent;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-nav a.active {
    background: rgba(215,36,40,0.14);
    border-left-color: var(--brand-accent);
    color: #fff;
}
.sidebar-nav .icon { width: 20px; text-align: center; font-size: 16px; }
.sidebar-footer { padding: 14px 20px; font-size: 12px; opacity: 0.6; border-top: 1px solid rgba(255,255,255,0.1); }

.main-content {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ---------------- Top bar ---------------- */
.topbar {
    height: var(--header-height);
    background: #fff;
    border-bottom: 1px solid #e3e9eb;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 900;
}
.hamburger {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--brand-primary-dark);
}
.global-search {
    flex: 1;
    max-width: 480px;
    position: relative;
}
.global-search input {
    width: 100%;
    padding: 10px 14px 10px 38px;
    border-radius: 999px;
    border: 1px solid #dbe3e6;
    background: var(--bg-light);
    font-size: 14px;
}
.global-search .search-icon {
    position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
    color: #8aa0a6;
}
.search-results-dropdown {
    position: absolute;
    top: 44px; left: 0; right: 0;
    background: #fff;
    border: 1px solid #e3e9eb;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    max-height: 420px;
    overflow-y: auto;
    display: none;
    z-index: 950;
}
.search-results-dropdown.show { display: block; }
.search-results-dropdown .group-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
    color: #8aa0a6; padding: 10px 14px 4px;
}
.search-results-dropdown a.result-item {
    display: block; padding: 8px 14px; font-size: 13.5px; color: #1c2b30;
}
.search-results-dropdown a.result-item:hover { background: var(--bg-light); }
.search-results-dropdown a.result-item small { display: block; color: #8aa0a6; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 16px; }
.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 13.5px; }
.topbar-user .avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--brand-primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px;
}
.topbar-user .role-tag { color: #8aa0a6; font-size: 11.5px; }

.page-body { padding: 22px 24px 60px; }

/* ---------------- Cards ---------------- */
.card {
    background: #fff;
    border-radius: var(--radius);
    border: 1px solid #e9eff0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}
.card-header {
    padding: 16px 18px;
    border-bottom: 1px solid #eef2f3;
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-body { padding: 18px; }

/* ---------------- Stat cards ---------------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}
.stat-card {
    background: #fff;
    border-radius: var(--radius);
    border: 1px solid #e9eff0;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 14px;
}
.stat-card .stat-icon {
    width: 46px; height: 46px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; flex-shrink: 0;
}
.stat-card .stat-value { font-size: 24px; font-weight: 700; line-height: 1.1; }
.stat-card .stat-label { font-size: 12.5px; color: #6d8288; margin-top: 2px; }

.icon-teal   { background: rgba(27,79,114,0.1); color: var(--brand-primary); }
.icon-amber  { background: rgba(232,164,25,0.15); color: #a1690b; }
.icon-red    { background: rgba(215,36,40,0.12); color: var(--brand-danger); }
.icon-green  { background: rgba(30,142,90,0.12); color: var(--brand-success); }
.icon-blue   { background: rgba(44,123,229,0.12); color: var(--brand-info); }

/* ---------------- Quick actions ---------------- */
.quick-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 22px; }
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 11px 18px; border-radius: 10px;
    font-size: 14px; font-weight: 600; border: none; cursor: pointer;
    transition: filter 0.15s ease;
}
.btn:hover { filter: brightness(0.94); }
.btn-primary { background: var(--brand-primary); color: #fff; }
.btn-accent { background: var(--brand-accent); color: #fff; }
.btn-outline { background: #fff; border: 1px solid #d6dee0; color: #1c2b30; }
.btn-success { background: var(--brand-success); color: #fff; }
.btn-danger { background: var(--brand-danger); color: #fff; }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------------- Tables ---------------- */
.table-responsive { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.8px; }
table.data-table th {
    text-align: left; padding: 12px 14px; background: #f6f9fa;
    color: #52686e; font-weight: 600; font-size: 12.5px;
    text-transform: uppercase; letter-spacing: 0.03em;
    border-bottom: 1px solid #e9eff0; white-space: nowrap;
}
table.data-table td {
    padding: 12px 14px; border-bottom: 1px solid #f0f4f5; vertical-align: middle;
}
table.data-table tr:hover td { background: #fafcfc; }
table.data-table .row-action { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------------- Badges ---------------- */
.badge {
    display: inline-block; padding: 4px 10px; border-radius: 999px;
    font-size: 11.5px; font-weight: 700; letter-spacing: 0.02em;
}
.badge-success { background: rgba(30,142,90,0.14); color: var(--brand-success); }
.badge-danger  { background: rgba(215,36,40,0.14); color: var(--brand-danger); }
.badge-warning { background: rgba(232,164,25,0.18); color: #a1690b; }
.badge-info    { background: rgba(44,123,229,0.14); color: var(--brand-info); }
.badge-secondary { background: #eef2f3; color: #64787e; }
.badge-primary-soft { background: rgba(27,79,114,0.12); color: var(--brand-primary); }

/* ---------------- Forms ---------------- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: #35474c; }
.form-control {
    width: 100%; padding: 11px 13px; border-radius: 8px;
    border: 1px solid #d6dee0; font-size: 14.5px; background: #fff;
}
.form-control:focus { outline: none; border-color: var(--brand-primary); box-shadow: 0 0 0 3px rgba(27,79,114,0.12); }
textarea.form-control { min-height: 90px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.form-hint { font-size: 12px; color: #8aa0a6; margin-top: 4px; }

/* ---------------- Tabs ---------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid #e3e9eb; margin-bottom: 18px; overflow-x: auto; }
.tabs a {
    padding: 11px 16px; font-size: 13.8px; font-weight: 600; color: #6d8288;
    border-bottom: 3px solid transparent; white-space: nowrap;
}
.tabs a.active { color: var(--brand-primary); border-bottom-color: var(--brand-primary); }

/* ---------------- Alerts / flash ---------------- */
.alert { padding: 13px 16px; border-radius: 8px; font-size: 14px; margin-bottom: 18px; }
.alert-success { background: rgba(30,142,90,0.1); color: #17694a; border: 1px solid rgba(30,142,90,0.25); }
.alert-danger { background: rgba(215,36,40,0.1); color: #a8291f; border: 1px solid rgba(215,36,40,0.25); }
.alert-info { background: rgba(44,123,229,0.1); color: #205a9c; border: 1px solid rgba(44,123,229,0.25); }

/* ---------------- Page header ---------------- */
.page-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 18px; }
.page-header h1 { font-size: 21px; margin: 0; }
.page-header .subtitle { color: #6d8288; font-size: 13.5px; margin-top: 2px; }

/* ---------------- Login page ---------------- */
.login-shell {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--brand-primary-dark), var(--brand-primary));
    padding: 20px;
}
.login-card {
    background: #fff; border-radius: 16px; padding: 40px 36px;
    width: 100%; max-width: 400px; box-shadow: 0 20px 50px rgba(0,0,0,0.25);
    text-align: center;
}
.login-card img.logo { height: 64px; margin-bottom: 8px; }
.login-card h1 { font-size: 18px; margin: 4px 0 2px; }
.login-card p.tag { color: #8aa0a6; font-size: 13px; margin-bottom: 24px; }
.login-card .form-group { text-align: left; }

/* ---------------- Empty state ---------------- */
.empty-state { text-align: center; padding: 40px 20px; color: #8aa0a6; }
.empty-state .icon { font-size: 40px; margin-bottom: 10px; }

/* ---------------- Client site chips ---------------- */
.site-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--bg-light); font-size: 12.8px; margin: 3px 4px 3px 0; }

/* ---------------- Utility ---------------- */
.text-muted { color: #8aa0a6; }
.text-danger { color: var(--brand-danger); }
.text-success { color: var(--brand-success); }
.mb-0 { margin-bottom: 0 !important; }
.d-flex { display: flex; }
.gap-2 { gap: 8px; }
.flex-wrap { flex-wrap: wrap; }
.justify-between { justify-content: space-between; }
.align-center { align-items: center; }

/* =====================================================================
   INVOICE MODULE
   ===================================================================== */

/* ---- Line-item builder ---- */
.line-items-table { width: 100%; border-collapse: collapse; }
.line-items-table th {
    text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em;
    color: #6d8288; padding: 8px 6px; border-bottom: 1px solid #e9eff0;
}
.line-items-table td { padding: 6px; vertical-align: top; }
.line-items-table input, .line-items-table select { padding: 8px 10px; font-size: 13.5px; }
.line-items-table .col-desc { width: 40%; }
.line-items-table .col-qty { width: 10%; }
.line-items-table .col-price { width: 14%; }
.line-items-table .col-amount { width: 14%; text-align: right; font-weight: 600; padding-top: 14px; white-space: nowrap; }
.line-items-table .col-action { width: 6%; text-align: center; }
.remove-line-btn {
    background: none; border: none; color: var(--brand-danger); cursor: pointer;
    font-size: 16px; padding: 6px;
}
.totals-box { max-width: 340px; margin-left: auto; margin-top: 16px; }
.totals-box .totals-row { display: flex; justify-content: space-between; padding: 7px 0; font-size: 14px; }
.totals-box .totals-row.total { border-top: 2px solid #1c2b30; margin-top: 6px; padding-top: 12px; font-size: 18px; font-weight: 700; }
.totals-box .totals-row.balance { color: var(--brand-danger); font-weight: 700; }

/* ---- GST toggle ---- */
.gst-toggle-group { display: flex; gap: 10px; margin-bottom: 16px; }
.gst-toggle-option {
    flex: 1; border: 2px solid #d6dee0; border-radius: 10px; padding: 14px;
    cursor: pointer; text-align: center; font-weight: 600; font-size: 13.5px;
}
.gst-toggle-option.active { border-color: var(--brand-primary); background: rgba(27,79,114,0.06); color: var(--brand-primary); }

/* ---- AI create invoice box ---- */
.ai-box {
    background: linear-gradient(135deg, rgba(27,79,114,0.06), rgba(215,36,40,0.04));
    border: 1px solid rgba(27,79,114,0.18);
    border-radius: 14px;
    padding: 20px;
}
.ai-box textarea { min-height: 110px; font-size: 14.5px; }
.ai-parse-result { background: #fff; border-radius: 10px; border: 1px solid #e9eff0; padding: 16px; margin-top: 14px; }
.ai-parse-field { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid #f4f7f8; font-size: 13.8px; }
.ai-parse-field .label { color: #6d8288; font-weight: 600; }
.ai-missing { color: var(--brand-danger); font-weight: 700; }
.ai-disclaimer { font-size: 12px; color: #8aa0a6; margin-top: 10px; }

/* ---- Invoice preview (mirrors the printable/PDF layout) ---- */
.invoice-preview { background: #fff; border-radius: var(--radius); border: 1px solid #e9eff0; padding: 40px; max-width: 850px; margin: 0 auto; }
.invoice-preview .inv-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; flex-wrap: wrap; }
.invoice-preview .inv-top img.logo { height: 56px; }
.invoice-preview .inv-company-block { font-size: 12.5px; color: #52686e; margin-top: 8px; line-height: 1.5; }
.invoice-preview .inv-number-block { text-align: right; font-size: 13px; color: #52686e; }
.invoice-preview .inv-number-block .inv-number { font-size: 15px; font-weight: 700; color: #1c2b30; }
.invoice-preview .inv-divider { height: 6px; background: var(--brand-primary); border-radius: 3px; margin: 24px 0; }
.invoice-preview h2.inv-business-name { font-size: 24px; margin: 0 0 10px; }
.invoice-preview .inv-payment-highlight { background: #fff7d6; padding: 10px 14px; border-radius: 8px; font-size: 13px; line-height: 1.6; margin-bottom: 20px; }
.invoice-preview .inv-meta-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 20px; margin-bottom: 24px; font-size: 13.5px; }
.invoice-preview .inv-meta-grid .meta-label { font-weight: 700; margin-bottom: 4px; }
.invoice-preview table.inv-items { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.invoice-preview table.inv-items th { text-align: left; font-size: 12px; text-transform: uppercase; color: #6d8288; padding: 8px 4px; border-bottom: 2px solid #1c2b30; }
.invoice-preview table.inv-items td { padding: 10px 4px; border-bottom: 1px solid #f0f4f5; font-size: 14px; vertical-align: top; }
.invoice-preview table.inv-items td.num { text-align: right; white-space: nowrap; }
.invoice-preview .inv-desc-sub { color: #8aa0a6; font-size: 12.5px; font-style: italic; }
.invoice-preview .inv-totals { max-width: 320px; margin-left: auto; }
.invoice-preview .inv-totals .row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; }
.invoice-preview .inv-totals .row.total { border-top: 2px solid #1c2b30; margin-top: 8px; padding-top: 14px; }
.invoice-preview .inv-totals .row.total .label { font-size: 20px; font-weight: 700; }
.invoice-preview .inv-totals .row.total .value { font-size: 20px; font-weight: 700; }
.invoice-preview .inv-gst-note { font-size: 12.5px; color: #6d8288; margin-top: 4px; }
.invoice-preview .inv-footer { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 40px; padding-top: 20px; border-top: 1px solid #eef2f3; gap: 20px; flex-wrap: wrap; }
.invoice-preview .inv-qr img { width: 100px; height: 100px; }
.invoice-preview .inv-pay-online { font-size: 12.5px; max-width: 320px; }
.invoice-preview .inv-pay-online a { color: var(--brand-primary); word-break: break-all; }
@media print {
    .no-print { display: none !important; }
    .invoice-preview { border: none; padding: 0; max-width: 100%; }
    body, .page-body { background: #fff; padding: 0; }
}

/* ---------------- Mobile ---------------- */
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; width: 100%; }
    .hamburger { display: block; }
    .form-row, .form-row-3 { grid-template-columns: 1fr; }
    .global-search { max-width: none; }
    .page-body { padding: 16px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .sidebar-backdrop {
        display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 999;
    }
    .sidebar-backdrop.show { display: block; }
    .invoice-preview { padding: 20px; }
    .invoice-preview .inv-meta-grid { grid-template-columns: 1fr; gap: 10px; }
    .line-items-table .col-desc, .line-items-table .col-qty, .line-items-table .col-price { display: block; width: 100%; }
    .line-items-table thead { display: none; }
    .line-items-table tr { display: block; border-bottom: 2px solid #eef2f3; padding-bottom: 10px; margin-bottom: 10px; }
    .line-items-table td { display: block; width: 100%; padding: 4px 0; }
}

/* ---------------- Tablet / iPad ---------------- */
/* iPad landscape & small laptops: slimmer menu so forms get more room */
@media (min-width: 901px) and (max-width: 1280px), (pointer: coarse) and (min-width: 901px) and (max-width: 1400px) {
    :root { --sidebar-width: 210px; }
    .page-body { padding: 18px 18px 50px; }
    .sidebar-nav a { padding-left: 16px; padding-right: 14px; }
}
/* iPad portrait (and phones turned sideways): two/three columns instead of one very long column */
@media (min-width: 600px) and (max-width: 900px) {
    .form-row { grid-template-columns: 1fr 1fr; }
    .form-row-3 { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 700px) and (max-width: 900px) {
    .form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
}
/* Touch screens (iPad / iPhone): finger-sized controls, and 16px text so Safari doesn't zoom in on every tap */
@media (pointer: coarse) {
    .form-control, .line-items-table input, .line-items-table select { font-size: 16px; min-height: 44px; }
    .btn { min-height: 44px; }
    .btn-sm { min-height: 38px; }
    .sidebar-nav a { padding-top: 13px; padding-bottom: 13px; }
}
/* Menu button on every screen size: on wide screens (iPad landscape / desktop) it hides or shows the side menu */
.hamburger { display: block; min-width: 40px; min-height: 40px; border-radius: 8px; }
.hamburger:hover { background: var(--bg-light); }
.main-content { transition: margin-left 0.25s ease, width 0.25s ease; }
@media (min-width: 901px) {
    html.menu-hidden .sidebar { transform: translateX(-100%); }
    html.menu-hidden .main-content { margin-left: 0; width: 100%; }
}
/* Long names / site addresses wrap inside their own column on the invoice */
.invoice-preview .inv-meta-grid > div { min-width: 0; overflow-wrap: anywhere; }

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .topbar { padding: 0 14px; gap: 10px; }
    .topbar-user span.name-text { display: none; }
    .gst-toggle-group { flex-direction: column; }
}
