/* ============================================================
   SIWAY Invoice Manager – app.css
   Design system: Bootstrap 5 base + custom layer
   ============================================================ */

/* ── Design tokens ─────────────────────────────────────────── */
:root {
    --sidebar-width:     240px;
    --topbar-height:     56px;

    /* Brand */
    --brand-orange:      #F07D1F;
    --brand-orange-dark: #D96B10;
    --brand-orange-pale: #fff8f2;
    --brand-orange-ring: rgba(240,125,31,.15);
    --brand-dark:        #1e1e1e;
    --brand-dark-hover:  #2a2a2a;

    /* Neutral */
    --gray-50:  #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    /* Status */
    --success-bg:  #d1fae5;
    --success-fg:  #065f46;
    --warning-bg:  #fef3c7;
    --warning-fg:  #92400e;
    --danger-bg:   #fee2e2;
    --danger-fg:   #991b1b;
    --neutral-bg:  #e5e7eb;
    --neutral-fg:  #374151;

    /* Surfaces */
    --surface:        #ffffff;
    --surface-subtle: #f2f3f5;
    --border:         #f0f0f0;
    --border-strong:  #e5e7eb;

    /* Shadows */
    --shadow-sm:  0 1px 4px rgba(0,0,0,.06);
    --shadow-md:  0 2px 8px rgba(0,0,0,.08);
    --shadow-lg:  0 8px 24px rgba(0,0,0,.10);

    /* Legacy aliases (used by existing views) */
    --brand-gray:       #808285;
    --brand-gray-light: #f0f0f0;

    /* Radius */
    --radius-sm:  6px;
    --radius-md:  10px;
    --radius-lg:  14px;
    --radius-xl:  18px;

    /* Transition */
    --transition: .15s ease;
}

/* ── Base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
    background: var(--surface-subtle);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: .9rem;
    color: var(--gray-800);
    -webkit-font-smoothing: antialiased;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--brand-dark);
    position: fixed;
    top: 0; left: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    transition: transform .28s cubic-bezier(.4,0,.2,1);
    overflow: hidden;
}

.sidebar-brand {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,.07);
    display: flex;
    align-items: center;
    gap: .85rem;
    flex-shrink: 0;
}

.brand-icon {
    flex-shrink: 0;
    width: 38px; height: 38px;
    background: var(--brand-orange);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    color: #fff;
    box-shadow: 0 2px 10px rgba(240,125,31,.45);
}

.brand-text-wrap { display: flex; flex-direction: column; gap: .1rem; }

.brand-name {
    font-size: .9rem;
    font-weight: 800;
    color: #fff;
    letter-spacing: .4px;
    line-height: 1;
}
.brand-name span { color: var(--brand-orange); }

.brand-sub {
    font-size: .58rem;
    font-weight: 600;
    color: rgba(255,255,255,.28);
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

.sidebar-nav {
    flex: 1;
    padding: .75rem 0;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.1) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 4px; }

.nav-section {
    padding: .6rem 1.25rem .35rem;
    font-size: .62rem;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: rgba(255,255,255,.28);
    font-weight: 700;
    margin-top: .25rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .58rem 1.5rem;
    color: rgba(255,255,255,.58);
    text-decoration: none;
    font-size: .855rem;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: all var(--transition);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-link:hover {
    color: #fff;
    background: rgba(255,255,255,.06);
    border-left-color: rgba(240,125,31,.45);
}

.sidebar-link.active {
    color: #fff;
    background: rgba(240,125,31,.13);
    border-left-color: var(--brand-orange);
    font-weight: 600;
}

.sidebar-link i {
    width: 18px;
    text-align: center;
    font-size: .95rem;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: .875rem 1.5rem;
    border-top: 1px solid rgba(255,255,255,.07);
    font-size: .78rem;
    color: rgba(255,255,255,.42);
    flex-shrink: 0;
}
.sidebar-footer a:hover { opacity: .85; }

/* ── Sidebar mobile overlay ────────────────────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 199;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity .28s ease;
}
.sidebar-overlay.visible {
    display: block;
    opacity: 1;
}

/* ── Main content ──────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── Topbar ────────────────────────────────────────────────── */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border-strong);
    padding: 0 1.75rem;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 1rem;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: .75rem;
    min-width: 0;
}

.topbar-title {
    font-weight: 600;
    font-size: .95rem;
    color: var(--gray-900);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-shrink: 0;
    font-size: .8rem;
    color: var(--gray-500);
}

/* Hamburger button */
.btn-sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    color: var(--gray-700);
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
    padding: 0;
}
.btn-sidebar-toggle:hover {
    background: var(--gray-200);
    color: var(--gray-900);
}
.btn-sidebar-toggle i { font-size: 1.1rem; }

/* ── Content area ──────────────────────────────────────────── */
.content-area {
    padding: 1.75rem 2rem;
    flex: 1;
}

/* ── Page header helper ────────────────────────────────────── */
.page-header {
    margin-bottom: 1.5rem;
}
.page-header h1,
.page-header h5 {
    font-weight: 700;
    color: var(--gray-900);
    margin: 0;
}

/* ── Cards ─────────────────────────────────────────────────── */
.page-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    padding: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.stat-card .stat-label {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--gray-500);
    font-weight: 600;
    margin-bottom: .4rem;
}

.stat-card .stat-value {
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--brand-dark);
    line-height: 1;
}

.stat-card .stat-icon {
    width: 44px; height: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

/* ── Table card ────────────────────────────────────────────── */
.table-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow: hidden;
}

.table-card .table-responsive { border-radius: 0; }

.table-card .table { margin: 0; }

.table-card .table thead th {
    background: #f8f8f8;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--gray-500);
    border-bottom: 1px solid #ebebeb;
    font-weight: 700;
    padding: .8rem 1rem;
    white-space: nowrap;
}

.table-card .table tbody td {
    padding: .8rem 1rem;
    vertical-align: middle;
    font-size: .87rem;
    border-bottom: 1px solid #f5f5f5;
    color: var(--gray-800);
}

.table-card .table tbody tr:last-child td { border-bottom: none; }
.table-card .table tbody tr:hover td { background: #fdf9f6; }

/* ── Badges ─────────────────────────────────────────────────── */
.badge-paid    { background: var(--success-bg); color: var(--success-fg); }
.badge-pending { background: var(--warning-bg); color: var(--warning-fg); }
.badge-other   { background: var(--neutral-bg); color: var(--neutral-fg); }
.badge-admin   { background: #fff0e5; color: #c45a00; }
.badge-finance { background: var(--gray-100); color: var(--gray-600); }

.badge-success { background: var(--success-bg); color: var(--success-fg); }
.badge-error   { background: var(--danger-bg);  color: var(--danger-fg);  }
.badge-warning { background: var(--warning-bg); color: var(--warning-fg); }
.badge-stale   { background: var(--gray-100);   color: var(--gray-500);   }
.badge-running { background: #dbeafe; color: #1e40af; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn-ovh {
    background: var(--brand-dark);
    color: #fff;
    border: none;
    font-weight: 600;
    transition: background var(--transition);
}
.btn-ovh:hover,
.btn-ovh:focus { background: var(--brand-dark-hover); color: #fff; }
.btn-ovh:focus-visible { outline: 2px solid var(--brand-orange); outline-offset: 2px; }

/* Override Bootstrap primary */
.btn-primary {
    background-color: var(--brand-orange) !important;
    border-color: var(--brand-orange) !important;
    color: #fff !important;
    font-weight: 600;
}
.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--brand-orange-dark) !important;
    border-color: var(--brand-orange-dark) !important;
}
.btn-primary:focus-visible { outline: 2px solid var(--brand-orange); outline-offset: 2px; }

/* Icon buttons */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px; height: 32px;
    padding: 0;
    border-radius: var(--radius-sm);
    border: 1px solid var(--gray-200);
    background: var(--surface);
    color: var(--gray-600);
    cursor: pointer;
    transition: all var(--transition);
    font-size: .875rem;
    text-decoration: none;
}
.btn-icon:hover { background: var(--gray-100); color: var(--gray-900); border-color: var(--gray-300); }
.btn-icon.btn-icon-danger:hover { background: var(--danger-bg); color: var(--danger-fg); border-color: #fca5a5; }
.btn-icon.btn-icon-warning:hover { background: var(--warning-bg); color: var(--warning-fg); border-color: #fcd34d; }

/* ── Forms – unified layer on top of Bootstrap ─────────────── */
.form-label {
    font-size: .8rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: .35rem;
}

.form-text {
    font-size: .73rem;
    color: var(--gray-400);
    margin-top: .25rem;
}

.form-control,
.form-select {
    font-size: .875rem;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-md);
    background: #fafafa;
    color: var(--gray-900);
    padding: .5rem .8rem;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--brand-dark);
    box-shadow: 0 0 0 3px var(--brand-orange-ring);
    background: var(--surface);
    outline: none;
}

.form-control::placeholder { color: var(--gray-400); }

.form-control.is-invalid,
.form-select.is-invalid {
    border-color: #ef4444;
    background: #fff;
}

.form-control.is-invalid:focus,
.form-select.is-invalid:focus {
    box-shadow: 0 0 0 3px rgba(239,68,68,.12);
}

.invalid-feedback {
    font-size: .75rem;
    color: #ef4444;
    display: flex;
    align-items: center;
    gap: .3rem;
    margin-top: .3rem;
}

/* Input groups */
.input-group .form-control:focus { z-index: 3; }

.input-group-text {
    background: var(--gray-100);
    border: 1.5px solid var(--gray-200);
    color: var(--gray-500);
    font-size: .875rem;
}

.input-group > .form-control {
    border-left: none;
}
.input-group > .input-group-text + .form-control {
    border-left: none;
}
.input-group > .input-group-text {
    border-right: none;
}

/* Form switch */
.form-check-input:checked {
    background-color: var(--brand-orange);
    border-color: var(--brand-orange);
}
.form-check-input:focus {
    box-shadow: 0 0 0 3px var(--brand-orange-ring);
    border-color: var(--brand-orange);
}

/* Textarea */
textarea.form-control { resize: vertical; min-height: 90px; }

/* Form section divider */
.form-section-label {
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--brand-orange);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: .4rem;
}

/* ── Pagination ────────────────────────────────────────────── */
.page-item.active .page-link {
    background: var(--brand-dark);
    border-color: var(--brand-dark);
    color: #fff;
}
.page-link {
    color: var(--brand-dark);
    border-radius: var(--radius-sm) !important;
    font-size: .83rem;
    padding: .35rem .65rem;
    border-color: var(--gray-200);
    transition: all var(--transition);
}
.page-link:hover { color: var(--brand-orange); background: var(--brand-orange-pale); border-color: var(--gray-300); }
.page-link:focus { box-shadow: 0 0 0 3px var(--brand-orange-ring); }

.pagination { gap: 3px; }

/* ── Breadcrumbs ───────────────────────────────────────────── */
.breadcrumb {
    background: none;
    padding: 0;
    margin: 0;
    font-size: .78rem;
}
.breadcrumb-item + .breadcrumb-item::before { color: var(--gray-400); }
.breadcrumb-item a { color: var(--gray-500); text-decoration: none; }
.breadcrumb-item a:hover { color: var(--brand-orange); }
.breadcrumb-item.active { color: var(--gray-700); font-weight: 500; }

/* ── Alerts ────────────────────────────────────────────────── */
.alert {
    font-size: .875rem;
    border-radius: var(--radius-md);
    border: none;
    padding: .75rem 1rem;
}
.alert-dismissible .btn-close { padding: .8rem; }
.alert-danger { background: var(--danger-bg); color: var(--danger-fg); }
.alert-success { background: var(--success-bg); color: var(--success-fg); }
.alert-warning { background: var(--warning-bg); color: var(--warning-fg); }
.alert-info { background: #dbeafe; color: #1e40af; }

/* ── Utilities ─────────────────────────────────────────────── */
.text-primary  { color: var(--brand-orange) !important; }
.bg-primary    { background: var(--brand-orange) !important; }
.border-primary { border-color: var(--brand-orange) !important; }

.text-brand-dark { color: var(--brand-dark); }

.divider { height: 1px; background: var(--border-strong); margin: 1.5rem 0; }

/* Loading spinner overlay */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,.7);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: inherit;
    z-index: 10;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--gray-400);
}
.empty-state i { font-size: 2.5rem; display: block; margin-bottom: .75rem; }
.empty-state p { font-size: .87rem; margin: 0; }

/* ── Flash banners (topbar area) ───────────────────────────── */
.topbar-alerts { padding: .75rem 2rem 0; }
.topbar-alerts .alert { margin-bottom: .5rem; }

/* ── Table responsive wrapper ──────────────────────────────── */
.table-responsive {
    -webkit-overflow-scrolling: touch;
}

/* Checkbox column */
.col-check { width: 40px; padding-left: 1rem !important; padding-right: .5rem !important; }

/* ── Code / monospace ──────────────────────────────────────── */
code {
    background: var(--gray-100);
    color: var(--gray-800);
    padding: .1rem .35rem;
    border-radius: 4px;
    font-size: .82rem;
}

/* ── Modals ────────────────────────────────────────────────── */
.modal-content {
    border-radius: var(--radius-xl);
    border: none;
    box-shadow: var(--shadow-lg);
}
.modal-header {
    border-bottom: 1px solid var(--border-strong);
    padding: 1.1rem 1.5rem;
}
.modal-footer {
    border-top: 1px solid var(--border-strong);
    padding: 1rem 1.5rem;
}
.modal-title { font-size: .95rem; font-weight: 700; }

/* ── Dropdowns ─────────────────────────────────────────────── */
.dropdown-menu {
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow-md);
    border-radius: var(--radius-md);
    font-size: .875rem;
    padding: .4rem;
}
.dropdown-item {
    border-radius: var(--radius-sm);
    padding: .4rem .75rem;
    transition: background var(--transition);
}
.dropdown-item:hover { background: var(--gray-100); }
.dropdown-item.active,
.dropdown-item:active { background: var(--brand-orange); color: #fff; }

/* ── ================================================================
   RESPONSIVE
   ================================================================ */

/* Tablet (< 992px) */
@media (max-width: 991.98px) {
    :root { --sidebar-width: 240px; }

    .content-area { padding: 1.25rem 1.5rem; }
    .topbar { padding: 0 1.25rem; }
    .topbar-alerts { padding: .75rem 1.5rem 0; }

    .stat-card .stat-value { font-size: 1.4rem; }
}

/* Mobile (< 768px) */
@media (max-width: 767.98px) {
    .sidebar {
        transform: translateX(-100%);
        z-index: 300;
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,.25);
    }

    .main-content { margin-left: 0; }

    .btn-sidebar-toggle { display: inline-flex; }

    .content-area { padding: 1rem; }
    .topbar { padding: 0 1rem; height: 52px; }
    .topbar-alerts { padding: .5rem 1rem 0; }
    .topbar-title { font-size: .9rem; }
    .topbar-right .topbar-clock-label { display: none; }

    /* Cards full bleed on mobile */
    .page-card { padding: 1.25rem; }
    .stat-card  { padding: 1rem 1.25rem; }

    /* Tables: horizontal scroll */
    .table-card { border-radius: var(--radius-md); }
    .table-card .table thead th { font-size: .68rem; padding: .65rem .75rem; }
    .table-card .table tbody td { font-size: .82rem; padding: .65rem .75rem; }

    /* Hide non-essential table columns on mobile */
    .col-mobile-hide { display: none; }

    /* Grid: stack everything */
    .row .col-md-3,
    .row .col-md-4,
    .row .col-md-6 { margin-bottom: .75rem; }

    /* Pagination compact */
    .page-link { padding: .3rem .55rem; font-size: .8rem; }

    /* Modals full-width */
    .modal-dialog { margin: .5rem; max-width: calc(100% - 1rem); }
}

/* Small mobile (< 480px) */
@media (max-width: 479.98px) {
    .content-area { padding: .75rem; }
    .topbar { padding: 0 .75rem; }
    .topbar-alerts { padding: .5rem .75rem 0; }
    .topbar-right { font-size: .74rem; }
}

/* ── Print ─────────────────────────────────────────────────── */
@media print {
    .sidebar,
    .topbar,
    .btn,
    .pagination { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .content-area { padding: 0 !important; }
    .table-card { box-shadow: none; border: 1px solid #ccc; }
}
