/* =========================================
   CMS — Web Smart Technology theme
   Navy + Orange accent
   ========================================= */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #f3f4f6;
    color: #1f2937;
    font-size: 14px;
    line-height: 1.5;
}
a { color: #1e3a8a; text-decoration: none; }
a:hover { text-decoration: underline; }

:root {
    --navy: #1e3a8a;
    --navy-dark: #172554;
    --navy-light: #3b5bdb;
    --orange: #f97316;
    --orange-light: #fb923c;
    --grey-50: #f9fafb;
    --grey-100: #f3f4f6;
    --grey-200: #e5e7eb;
    --grey-300: #d1d5db;
    --grey-500: #6b7280;
    --grey-700: #374151;
    --grey-900: #111827;
    --green: #16a34a;
    --yellow: #ca8a04;
    --orange-warn: #ea580c;
    --red: #dc2626;
}

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

.sidebar {
    width: 240px;
    background: var(--navy-dark);
    color: #e0e7ff;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand {
    padding: 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 10px;
}
.brand-logo {
    width: 44px; height: 44px;
    border-radius: 50%;
    object-fit: cover;
    background: white;
    flex-shrink: 0;
    border: 2px solid var(--orange);
}
.brand-logo-placeholder {
    display: flex; align-items: center; justify-content: center;
    color: var(--navy-dark); font-weight: 700;
}
.brand-name { font-weight: 700; font-size: 14px; color: #fff; }
.brand-tag  { font-size: 11px; color: #94a3b8; }

.nav { padding: 12px 8px; flex: 1; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    color: #cbd5e1;
    border-radius: 6px;
    margin-bottom: 4px;
    font-size: 14px;
    transition: background 0.15s;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--orange); color: #fff; }
.nav-item .ic { font-size: 16px; width: 18px; display: inline-block; }

.sidebar-foot {
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 11px;
}
.sidebar-foot .muted { color: #94a3b8; margin-bottom: 4px; }

/* Main content */
.content { flex: 1; min-width: 0; }
.topbar {
    background: #fff;
    border-bottom: 1px solid var(--grey-200);
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.page-title { margin: 0; font-size: 18px; color: var(--navy-dark); }
.topbar-right { display: flex; gap: 16px; font-size: 13px; }
.muted { color: var(--grey-500); }
.muted-link { color: var(--grey-700); }
.page { padding: 24px; max-width: 1400px; }

/* =========================================
   Alerts
   ========================================= */
.alert {
    margin: 14px 24px 0;
    padding: 12px 16px;
    border-radius: 6px;
    font-size: 14px;
}
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }

/* =========================================
   Cards / Panels
   ========================================= */
.card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    margin-bottom: 18px;
    overflow: hidden;
}
.card-head {
    padding: 14px 18px;
    border-bottom: 1px solid var(--grey-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-head h2 { margin: 0; font-size: 16px; color: var(--navy-dark); }
.card-body { padding: 18px; }

/* =========================================
   Forms
   ========================================= */
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

.field { display: flex; flex-direction: column; }
.field label {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--grey-700);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.field input[type=text],
.field input[type=email],
.field input[type=number],
.field input[type=date],
.field input[type=password],
.field input[type=file],
.field textarea,
.field select {
    padding: 9px 11px;
    border: 1px solid var(--grey-300);
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
    font-family: inherit;
    width: 100%;
}
.field input:focus,
.field textarea:focus,
.field select:focus {
    outline: none;
    border-color: var(--navy);
    box-shadow: 0 0 0 3px rgba(30,58,138,0.1);
}
.field textarea { resize: vertical; min-height: 70px; }
.field .hint { font-size: 11px; color: var(--grey-500); margin-top: 4px; }

fieldset.section {
    border: 1px solid var(--grey-200);
    border-radius: 6px;
    padding: 14px 16px;
    margin-bottom: 16px;
}
fieldset.section legend {
    padding: 0 8px;
    color: var(--navy);
    font-weight: 600;
    font-size: 13px;
}

/* =========================================
   Buttons
   ========================================= */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    font-family: inherit;
    transition: opacity 0.15s, transform 0.05s;
}
.btn:hover { opacity: 0.9; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--navy); color: #fff; }
.btn-orange  { background: var(--orange); color: #fff; }
.btn-green   { background: var(--green); color: #fff; }
.btn-red     { background: var(--red); color: #fff; }
.btn-ghost   { background: #fff; color: var(--navy); border: 1px solid var(--grey-300); }
.btn-sm      { padding: 4px 10px; font-size: 12px; }

.actions-row { display: flex; gap: 8px; flex-wrap: wrap; }
/* =========================================
   Mobile Responsive — FIXED
   ========================================= */
.mobile-toggle { display: none; background: var(--navy-dark); color: #fff; border: none; padding: 8px 12px; font-size: 18px; cursor: pointer; border-radius: 6px; line-height: 1; }
.sidebar-backdrop { display: none; }

@media (max-width: 900px) {
    html, body { overflow-x: hidden; }
    .layout { display: block; }

    /* Sidebar = off-canvas drawer, FULLY hidden by default */
    .sidebar {
        position: fixed !important;
        top: 0; left: -260px;
        height: 100vh;
        width: 240px;
        z-index: 200;
        transition: left 0.25s ease;
        box-shadow: 2px 0 12px rgba(0,0,0,0.3);
    }
    .sidebar.open { left: 0; }
    .sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 150; }
    .sidebar-backdrop.show { display: block; }

    .content { width: 100%; margin-left: 0 !important; }
    .mobile-toggle { display: inline-block; }

    .topbar { padding: 10px 12px; gap: 8px; }
    .page-title { font-size: 15px; margin: 0; }
    .topbar-right { gap: 6px; font-size: 11px; flex-wrap: wrap; justify-content: flex-end; }
    .topbar-right .muted { display: none; }
    .topbar-right .muted-link { display: none; }
    .user-chip { padding: 3px 8px 3px 3px; font-size: 11px; }
    .user-avatar { width: 22px; height: 22px; font-size: 10px; }

    .page { padding: 10px; max-width: 100%; }
    .alert { margin: 8px 10px 0; padding: 9px 11px; font-size: 12px; }

    /* Grids stack */
    .grid, .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr !important; gap: 10px; }

    /* Tiles: 1 column on mobile so they fit fully */
    .tiles { grid-template-columns: 1fr !important; gap: 10px; margin-bottom: 14px; }
    .tile { padding: 14px; }
    .tile-value { font-size: 22px; }
    .tile-label { font-size: 10px; }
    .tile-sub { font-size: 11px; }

    /* Cards */
    .card { border-radius: 6px; margin-bottom: 12px; }
    .card-head { flex-direction: column; align-items: stretch; gap: 8px; padding: 12px; }
    .card-head h2 { font-size: 14px; }
    .card-body { padding: 12px; }

    /* Actions / Forms */
    .actions-row { flex-wrap: wrap; gap: 6px; }
    .actions-row form { flex: 1 1 100%; flex-wrap: wrap; }
    .actions-row input[type=text],
    .actions-row input[type=search] { min-width: 0 !important; flex: 1; width: 100%; }
    fieldset.section { padding: 10px; }
    .field input, .field textarea, .field select { font-size: 14px; padding: 8px 10px; }
    .field label { font-size: 11px; }
    .btn { padding: 7px 12px; font-size: 13px; }
    .btn-sm { padding: 5px 9px; font-size: 11px; }

    /* ============================================
       TABLES → stacked card layout on mobile
       Requires <td data-label="Column"> on each cell
       ============================================ */
  /* TABLES → stacked card layout on mobile */
.table-wrap { overflow: visible; }
table.data { background: transparent; border-collapse: separate; }

/* Fully hide the desktop header row */
table.data thead,
table.data thead tr,
table.data thead th { display: none !important; }

table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
table.data tr {
    background: #fff;
    border: 1px solid var(--grey-200);
    border-radius: 8px;
    margin-bottom: 10px;
    padding: 12px 14px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
table.data tr:hover td { background: transparent; }

/* Each cell becomes a label-on-top, value-below row */
table.data td {
    padding: 8px 0;
    border: none;
    border-bottom: 1px dashed var(--grey-200);
    text-align: left !important;
    font-size: 14px;
    word-break: break-word;
    display: block;
    position: static;
}
table.data td:last-child { border-bottom: none; padding-bottom: 0; }
table.data td:first-child { padding-top: 0; }

/* Label on its own line, above the value (NOT positioned absolute) */
table.data td::before {
    content: attr(data-label);
    display: block;
    font-weight: 600;
    font-size: 10px;
    color: var(--grey-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 3px;
}
/* Don't render the label line if data-label is empty */
table.data td:not([data-label])::before,
table.data td[data-label=""]::before { display: none; }

table.data td.num { text-align: left !important; }
table.data tr[style*="background"] { background: #e0e7ff !important; }

    /* Bill items input table — horizontal scroll instead */
    table.items-input { display: block; overflow-x: auto; white-space: nowrap; }
    table.items-input td input { font-size: 12px; padding: 5px 6px; min-width: 80px; }
    .totals-box { max-width: 100%; }

    /* Login */
    .login-card { padding: 28px 22px; max-width: 92%; }

    /* Print page */
    .print-page { padding: 18px 14px; margin: 8px; }
    .bill-head { flex-direction: column; text-align: center; gap: 10px; }
    .bill-type-tag { position: static; margin-top: 6px; align-self: flex-end; }
    .bill-web { text-align: center; }
    .bill-meta { flex-direction: column; gap: 14px; }
    .bill-co h1 { font-size: 22px; }
    table.bill-items { font-size: 11px; }
    table.bill-items th, table.bill-items td { padding: 6px 4px; }
    .bill-signs { flex-direction: column; gap: 40px; }
    .print-toolbar { padding: 10px 16px; flex-wrap: wrap; }
}

@media (max-width: 480px) {
    .topbar-right .user-chip span:not(.user-avatar) { display: none; }
    .actions-row .btn-sm { font-size: 11px; padding: 5px 8px; }
}
/* =========================================
   Tables
   ========================================= */
.table-wrap { overflow-x: auto; }
table.data {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
}
table.data th {
    background: var(--navy);
    color: #fff;
    padding: 10px 12px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    text-align: left;
    font-weight: 600;
}
table.data td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--grey-200);
    font-size: 13px;
    vertical-align: middle;
}
table.data tr:hover td { background: var(--grey-50); }
table.data .num { text-align: right; }
table.data .center { text-align: center; }

/* =========================================
   Badges
   ========================================= */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}
.badge-green  { background: #dcfce7; color: #166534; }
.badge-yellow { background: #fef3c7; color: #854d0e; }
.badge-orange { background: #ffedd5; color: #9a3412; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-grey   { background: var(--grey-200); color: var(--grey-700); }
.badge-navy   { background: #dbeafe; color: var(--navy-dark); }

/* =========================================
   Dashboard tiles
   ========================================= */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
@media (max-width: 900px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
.tile {
    background: #fff;
    padding: 18px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    border-left: 4px solid var(--navy);
}
.tile.warn    { border-left-color: var(--orange-warn); }
.tile.danger  { border-left-color: var(--red); }
.tile.success { border-left-color: var(--green); }
.tile-label   { font-size: 11px; color: var(--grey-500); text-transform: uppercase; letter-spacing: 0.4px; }
.tile-value   { font-size: 28px; font-weight: 700; color: var(--navy-dark); margin-top: 4px; }
.tile-sub     { font-size: 12px; color: var(--grey-500); margin-top: 4px; }

/* =========================================
   Modal (renewal popup, print-type popup)
   ========================================= */
.modal-bg {
    position: fixed; inset: 0;
    background: rgba(15,23,42,0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal-bg.show { display: flex; }
.modal {
    background: #fff;
    border-radius: 10px;
    width: 100%;
    max-width: 460px;
    padding: 0;
    overflow: hidden;
}
.modal-head {
    padding: 14px 18px;
    background: var(--navy);
    color: #fff;
    font-weight: 600;
}
.modal-body { padding: 18px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--grey-200); display: flex; gap: 8px; justify-content: flex-end; }

/* =========================================
   Image preview
   ========================================= */
.img-preview {
    max-width: 160px;
    max-height: 90px;
    border: 1px solid var(--grey-300);
    border-radius: 6px;
    padding: 6px;
    background: #fff;
    margin-top: 6px;
}

/* =========================================
   Print Layout (Bill style)
   ========================================= */
.print-page {
    background: #fff;
    max-width: 800px;
    margin: 20px auto;
    padding: 40px 50px;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    font-family: "Times New Roman", Georgia, serif;
    color: #1f2937;
}
.print-toolbar {
    max-width: 800px;
    margin: 0 auto;
    padding: 12px 50px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.bill-head {
    display: flex;
    align-items: center;
    gap: 18px;
    padding-bottom: 8px;
    border-bottom: 3px solid var(--orange);
    position: relative;
}
.bill-logo {
    width: 90px; height: 90px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--orange);
    background: #fff;
    flex-shrink: 0;
}
.bill-logo-placeholder {
    width: 90px; height: 90px;
    border-radius: 50%;
    border: 3px solid var(--orange);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; color: var(--navy);
    background: #fff;
    flex-shrink: 0;
}
.bill-co { flex: 1; }
.bill-co h1 {
    margin: 0;
    font-size: 30px;
    color: var(--navy-dark);
    font-family: "Times New Roman", Georgia, serif;
}
.bill-reg { color: var(--navy); font-weight: 700; font-size: 13px; margin-top: 2px; }
.bill-web { color: var(--red); font-weight: 700; font-size: 13px; margin-top: 8px; text-align: right; }

.bill-type-tag {
    position: absolute;
    top: 0;
    right: 0;
    background: var(--navy-dark);
    color: #fff;
    padding: 8px 18px;
    font-weight: 700;
    font-size: 14px;
}

.bill-info {
    margin-top: 6px;
    padding: 8px 0;
    font-weight: 700;
    color: var(--navy-dark);
    font-size: 13px;
    border-bottom: 1px solid var(--orange);
}

.bill-meta {
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
    gap: 20px;
}
.bill-billto {
    background: #e0e7ff;
    padding: 8px 14px;
    font-weight: 700;
    color: var(--navy-dark);
    margin-bottom: 6px;
    width: fit-content;
    min-width: 180px;
}
.bill-client { font-size: 13px; line-height: 1.6; }
.bill-client b { font-size: 15px; }

.bill-no-block {
    font-size: 13px;
    line-height: 1.6;
    min-width: 200px;
}
.bill-no-block .lbl { display: inline-block; width: 70px; font-weight: 700; }

table.bill-items {
    width: 100%;
    border-collapse: collapse;
    margin-top: 24px;
    font-size: 13px;
}
table.bill-items th {
    background: #e0e7ff;
    color: var(--navy-dark);
    padding: 10px 12px;
    border: 1px solid #c7d2fe;
    font-weight: 700;
    text-align: left;
}
table.bill-items td {
    padding: 12px;
    border: 1px solid #e0e7ff;
}
table.bill-items td.num { text-align: right; }
table.bill-items tfoot td {
    background: #e0e7ff;
    color: var(--navy-dark);
    font-weight: 700;
}
table.bill-items tfoot td.net {
    background: var(--navy-dark);
    color: #fff;
}

.bill-terms {
    margin-top: 24px;
    border: 1px solid var(--grey-300);
    padding: 12px 14px;
    font-size: 12px;
    line-height: 1.7;
}
.bill-terms h3 {
    margin: 0 0 6px 0;
    color: var(--navy-dark);
    border-bottom: 1px solid var(--grey-300);
    padding-bottom: 4px;
    font-size: 14px;
}

.bill-signs {
    margin-top: 80px;
    display: flex;
    justify-content: space-between;
    font-size: 13px;
}
.sign-block { text-align: center; min-width: 220px; }
.sign-block img { max-height: 50px; margin-bottom: 4px; }
.sign-line { border-top: 1px solid #333; padding-top: 4px; font-weight: 700; }

.bill-foot {
    margin-top: 40px;
    text-align: center;
    font-size: 11px;
    color: var(--grey-500);
}

/* Print styles */
@media print {
    body { background: #fff; }
    .sidebar, .topbar, .print-toolbar, .alert { display: none !important; }
    .layout { display: block; }
    .content, .page { padding: 0 !important; max-width: none !important; }
    .print-page {
        box-shadow: none;
        margin: 0;
        padding: 20px 30px;
        max-width: 100%;
    }
}

/* =========================================
   Item rows for bill creation
   ========================================= */
table.items-input {
    width: 100%;
    border-collapse: collapse;
    margin-top: 6px;
}
table.items-input th {
    background: var(--navy);
    color: #fff;
    padding: 8px 10px;
    font-size: 12px;
    text-align: left;
}
table.items-input td {
    padding: 6px 6px;
    border-bottom: 1px solid var(--grey-200);
    vertical-align: top;
}
table.items-input input {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--grey-300);
    border-radius: 4px;
    font-size: 13px;
}
.row-del { color: var(--red); cursor: pointer; font-size: 18px; background: none; border: none; }

.totals-box {
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
    max-width: 360px;
    margin-left: auto;
    margin-top: 12px;
    font-size: 14px;
}
.totals-box .tr { display: flex; justify-content: space-between; padding: 5px 10px; }
.totals-box .tr.final {
    background: var(--navy-dark);
    color: #fff;
    font-weight: 700;
    border-radius: 4px;
    font-size: 16px;
}
