/* ═══════════════════════════════════════════════════════════════════
   NexaERP — Main Stylesheet
   Navy / Gold corporate theme
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --brand:        #1A2B4A;
  --brand-mid:    #2D4A7A;
  --brand-light:  #4A72B0;
  --accent:       #E8A830;
  --accent-light: #F5C860;
  --success:      #2A8A5C;
  --danger:       #C0392B;
  --warning:      #D68910;
  --info:         #2471A3;
  --bg:           #F4F6FA;
  --bg2:          #EAECF2;
  --surface:      #FFFFFF;
  --border:       #D8DCE8;
  --border-strong:#B8BDD0;
  --text:         #1A2035;
  --text-muted:   #5A6278;
  --text-light:   #8A90A8;
  --sidebar-w:    248px;
  --header-h:     60px;
  --font:         'DM Sans', system-ui, sans-serif;
  --mono:         'DM Mono', 'Consolas', monospace;
  --radius:       8px;
  --radius-lg:    12px;
  --shadow:       0 1px 3px rgba(26,32,53,.08), 0 1px 1px rgba(26,32,53,.04);
  --shadow-md:    0 4px 12px rgba(26,32,53,.10), 0 2px 4px rgba(26,32,53,.06);
}

/* ── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { text-decoration: none; color: inherit; }
button, input, select, textarea { font-family: var(--font); }
img { max-width: 100%; }

/* ── Layout ─────────────────────────────────────────────────────── */
#app         { display: flex; height: 100vh; overflow: hidden; }
#main        { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
#content     { flex: 1; overflow-y: auto; padding: 24px; }

/* ── Sidebar ─────────────────────────────────────────────────────  */
#sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--brand); display: flex; flex-direction: column;
  overflow: hidden;
}
.sidebar-logo {
  height: var(--header-h); padding: 0 18px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.08); flex-shrink: 0;
}
.logo-mark {
  width: 34px; height: 34px; background: #fff;
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; padding: 3px; box-sizing: border-box;
}
.logo-mark img { width: 100%; height: 100%; object-fit: contain; display: block; }
.logo-text { font-size: 16px; font-weight: 600; color: #fff; letter-spacing: -.3px; }
.logo-sub  { font-size: 10px; color: rgba(255,255,255,.4); letter-spacing: .8px; text-transform: uppercase; margin-top: -1px; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 0; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 2px; }

.nav-section  { margin-bottom: 4px; }
.nav-label    { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: rgba(255,255,255,.3); padding: 12px 18px 4px; font-weight: 500; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 18px; color: rgba(255,255,255,.62);
  cursor: pointer; border-left: 3px solid transparent;
  font-size: 13px; transition: all .14s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: rgba(255,255,255,.9); }
.nav-item.active { background: rgba(255,255,255,.10); color: #fff; border-left-color: var(--accent); font-weight: 500; }
.nav-item svg { width: 15px; height: 15px; flex-shrink: 0; opacity: .85; }
.nav-item.active svg { opacity: 1; }
.nav-item .chevron { margin-left: auto; width: 13px; height: 13px; transition: transform .2s; }
.nav-item.open .chevron { transform: rotate(180deg); }

/* Submenu */
.nav-submenu { display: none; background: rgba(0,0,0,.15); padding: 2px 0; }
.nav-submenu.open { display: block; }
.nav-sub {
  display: block; padding: 7px 18px 7px 42px;
  color: rgba(255,255,255,.55); font-size: 12.5px; border-left: 3px solid transparent;
  transition: all .14s;
}
.nav-sub:hover { color: rgba(255,255,255,.85); background: rgba(255,255,255,.04); }
.nav-sub.active { color: #fff; border-left-color: var(--accent-light); background: rgba(255,255,255,.07); }

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
}
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-light); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; color: #fff; flex-shrink: 0; }
.user-name { font-size: 13px; font-weight: 500; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: rgba(255,255,255,.4); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logout-btn { color: rgba(255,255,255,.45); display: flex; padding: 4px; border-radius: 4px; transition: all .15s; }
.logout-btn:hover { color: #fff; background: rgba(255,255,255,.1); }

/* ── Header ──────────────────────────────────────────────────────  */
#header {
  height: var(--header-h); background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 22px; gap: 14px; flex-shrink: 0;
}
.page-title { font-size: 16px; font-weight: 600; color: var(--text); white-space: nowrap; }
.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.bc-item.active { color: var(--text); font-weight: 500; }
.bc-sep { color: var(--border-strong); }

/* Instance switcher */
.instance-switcher {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 5px 10px; font-size: 12.5px; color: var(--text-muted);
}
.instance-dd { border: none; background: none; font-size: 12.5px; color: var(--text); outline: none; cursor: pointer; max-width: 180px; }

/* Token status */
.token-status { font-size: 12px; }

.header-btn {
  width: 34px; height: 34px; border-radius: var(--radius);
  background: var(--bg); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); cursor: pointer; transition: all .15s;
}
.header-btn:hover { background: var(--bg2); color: var(--text); }

/* Token warning bar */
.token-warning-bar {
  background: #FEF9EC; border-bottom: 1px solid #F5C860;
  padding: 8px 22px; display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: #9A6B00; flex-shrink: 0;
}

/* ── Cards ───────────────────────────────────────────────────────  */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.card-header { padding: 14px 20px 12px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-title  { font-size: 14px; font-weight: 600; color: var(--text); }
.card-body   { padding: 20px; }
.mb-20       { margin-bottom: 20px; }
.mb-24       { margin-bottom: 24px; }

/* ── Stat Cards ──────────────────────────────────────────────────  */
.stats-grid   { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; }
.stat-card    { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px; box-shadow: var(--shadow); }
.stat-label   { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 500; margin-bottom: 6px; }
.stat-value   { font-size: 24px; font-weight: 600; color: var(--text); letter-spacing: -.5px; margin-bottom: 4px; }
.stat-change  { font-size: 12px; color: var(--text-muted); }

/* ── Toolbar ─────────────────────────────────────────────────────  */
.toolbar        { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar-search { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 7px 12px; flex: 1; max-width: 320px; }
.toolbar-search-input { border: none; background: none; outline: none; font-size: 13px; color: var(--text); width: 100%; }
.toolbar-search-input::placeholder { color: var(--text-light); }

/* ── Buttons ─────────────────────────────────────────────────────  */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: var(--radius); font-size: 13px; font-weight: 500; transition: all .15s; cursor: pointer; border: 1px solid transparent; line-height: 1.4; }
.btn svg { width: 14px; height: 14px; }
.btn-primary   { background: var(--brand);   color: #fff;          border-color: var(--brand); }
.btn-primary:hover  { background: var(--brand-mid); border-color: var(--brand-mid); }
.btn-secondary { background: var(--surface); color: var(--text);   border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-accent    { background: var(--accent);  color: var(--brand);  border-color: var(--accent); font-weight: 600; }
.btn-accent:hover { background: var(--accent-light); }
.btn-link      { background: none; border: none; color: var(--brand-light); padding-left: 0; padding-right: 0; }
.btn-sm        { padding: 5px 10px; font-size: 12px; }
.btn-block     { width: 100%; justify-content: center; }
.btn-icon      { padding: 5px; background: var(--bg); border: 1px solid var(--border); color: var(--text-muted); border-radius: var(--radius); cursor: pointer; display: inline-flex; align-items: center; }
.btn-icon:hover { background: var(--bg2); color: var(--text); }

/* ── Forms ───────────────────────────────────────────────────────  */
.form-group   { margin-bottom: 16px; }
.form-label   { display: block; font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 5px; }
.form-control { width: 100%; padding: 8px 11px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 13.5px; color: var(--text); background: var(--surface); outline: none; transition: border .15s; font-family: var(--font); }
.form-control:focus { border-color: var(--brand-light); box-shadow: 0 0 0 3px rgba(74,114,176,.12); }
.form-control-code { letter-spacing: 4px; font-size: 20px; text-align: center; font-family: var(--mono); }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ── Badges ──────────────────────────────────────────────────────  */
.badge       { display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; letter-spacing: .3px; white-space: nowrap; }
.badge-green { background: #EDFAF3; color: #1A7A4A; }
.badge-amber { background: #FEF9EC; color: #9A6B00; }
.badge-red   { background: #FDECEA; color: #A32020; }
.badge-blue  { background: #EEF4FF; color: #2D57B0; }
.badge-gray  { background: var(--bg2); color: var(--text-muted); }

/* ── Alerts ──────────────────────────────────────────────────────  */
.alert         { padding: 12px 16px; border-radius: var(--radius); font-size: 13px; margin-bottom: 16px; border: 1px solid; }
.alert-danger  { background: #FDECEA; color: #A32020; border-color: #F5B7B1; }
.alert-success { background: #EDFAF3; color: #1A7A4A; border-color: #A9DFBF; }
.alert-warning { background: #FEF9EC; color: #9A6B00; border-color: #F9E79F; }
.alert-info    { background: #EEF4FF; color: #2D57B0; border-color: #AED6F1; }

/* ── Tables / GridView ───────────────────────────────────────────  */
.table-wrap { overflow-x: auto; }
table.grid, .grid table, asp\.gridview table, table { width: 100%; border-collapse: collapse; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-muted); font-weight: 600; padding: 9px 14px; text-align: left; border-bottom: 1px solid var(--border); background: var(--bg); white-space: nowrap; }
td { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; color: var(--text); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #FAFBFD; }
.mono     { font-family: var(--mono); }
.td-muted { color: var(--text-muted); }
.text-right { text-align: right !important; }
.font-600   { font-weight: 600; }
.text-sm    { font-size: 12px; }
.text-muted { color: var(--text-muted); }

/* GridView pager */
.grid-pager td { text-align: center; padding: 10px; border: none; background: var(--bg); }
.grid-pager a, .grid-pager span { padding: 4px 8px; border-radius: 4px; font-size: 12px; }
.grid-pager a { color: var(--brand-light); }
.grid-pager span { background: var(--brand); color: #fff; font-weight: 600; }
.empty-row td { text-align: center; color: var(--text-muted); padding: 32px; font-size: 13px; }

/* ── Quick link cards (Dashboard) ────────────────────────────────  */
.quick-link-card {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 20px 16px; border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); cursor: pointer; transition: all .15s; text-align: center;
  color: var(--text-muted); font-size: 12.5px; font-weight: 500;
}
.quick-link-card:hover { border-color: var(--brand-light); background: #EEF4FF; color: var(--brand); }
.quick-link-card svg { color: var(--brand-light); }

/* ── Auth pages ──────────────────────────────────────────────────  */
.auth-body      { background: var(--brand); display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-container { width: 420px; }
.auth-logo      { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; justify-content: center; }
.auth-card      { background: var(--surface); border-radius: var(--radius-lg); padding: 28px; box-shadow: var(--shadow-md); margin-bottom: 12px; }
.auth-card-title { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.auth-card-sub   { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; line-height: 1.5; }

/* Instance list */
.instance-option {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 8px; width: 100%; cursor: pointer; transition: all .15s;
  background: var(--surface); color: var(--text);
}
.instance-option:hover { border-color: var(--brand-light); background: #EEF4FF; }
.instance-icon  { width: 36px; height: 36px; border-radius: 8px; background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; flex-shrink: 0; }
.instance-name  { font-weight: 600; font-size: 14px; }
.instance-id    { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.instance-option svg { margin-left: auto; color: var(--text-light); }

/* ── Grid layouts ────────────────────────────────────────────────  */
.grid-2  { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3  { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }

/* ── Responsive ──────────────────────────────────────────────────  */
/* ── Hamburger menu toggle (hidden on desktop) ─────────── */
#menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    color: var(--text);
    cursor: pointer;
    padding: 4px 8px;
    margin-right: 4px;
}
#sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 998;
}
#sidebar-overlay.show { display: block; }

/* ── Responsive breakpoints ────────────────────────────── */
@media (max-width: 1100px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
    /* Sidebar becomes a slide-in drawer */
    #menu-toggle { display: inline-block; }
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 999;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 2px 0 12px rgba(0,0,0,0.15);
    }
    #sidebar.open { transform: translateX(0); }
    #content { padding: 16px; }
    #header { padding: 0 14px; }

    /* Multi-column grids collapse to single column */
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }

    /* Form/detail grids reflow to one column */
    .card-body > div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }

    /* Filter rows wrap and inputs go full width */
    form[style*="flex"] { flex-wrap: wrap; }
    .form-control[style*="width"] { width: 100% !important; }
}

@media (max-width: 560px) {
    .stats-grid { grid-template-columns: 1fr; }
    .page-title { font-size: 14px; }
    .instance-dd { max-width: 110px; }

    /* Tables: let them scroll horizontally rather than crush */
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table-wrap table { min-width: 560px; }

    /* Stack action-button rows */
    .btn { padding: 8px 12px; }
}

/* ── Pagination ────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}
.page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 10px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s;
}
.page-btn:hover {
    background: var(--surface-alt);
}
.page-btn.active {
    background: var(--gold);
    color: #1a1a2e;
    border-color: var(--gold);
    font-weight: 600;
}
.page-btn.disabled {
    color: var(--text-muted);
    cursor: default;
    pointer-events: none;
    border-color: transparent;
    background: none;
}

/* ── Sort headers ──────────────────────────────────────── */
.sort-hdr {
    color: inherit;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    white-space: nowrap;
}
.sort-hdr:hover {
    color: var(--gold);
}

/* ── Inactive row fading ───────────────────────────────── */
tr.row-inactive {
    opacity: 0.45;
    background: var(--surface-alt) !important;
}

/* ── Danger button ─────────────────────────────────────── */
.btn-danger {
    background: #FCEBEC;
    color: #B3261E;
    border: 1px solid #F3C2C0;
}
.btn-danger:hover {
    background: #F8D7D8;
}

/* ── Unapplied payment highlight ───────────────────────── */
tr.row-unapplied td {
    background: #FFF8E6;
}
tr.row-unapplied:hover td {
    background: #FEF1CC;
}
tr.row-unapplied td:first-child {
    border-left: 3px solid #E0A800;
}

/* ── Breadcrumbs ───────────────────────────────────────── */
.breadcrumbs {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 16px;
    font-size: 13px;
}
.breadcrumbs a {
    color: var(--text-muted);
    text-decoration: none;
    padding: 3px 8px;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
}
.breadcrumbs a:hover {
    background: var(--surface-alt);
    color: var(--brand);
}
.breadcrumbs .crumb-sep {
    color: var(--text-muted);
    opacity: 0.5;
}
.breadcrumbs .crumb-current {
    color: var(--text);
    font-weight: 600;
    padding: 3px 8px;
}
