/*
 * Invoicing System - Application Stylesheet
 * No external dependencies. System font stack only. No CDN references.
 */

/* ==========================================================================
   Reset & Base
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; height: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    font-size: 0.9375rem;
    line-height: 1.5;
    color: #333;
    background: #f0f2f5;
    min-height: 100vh;
}

a { color: #2980b9; text-decoration: none; }
a:hover { text-decoration: underline; color: #1a5c8a; }

h1, h2, h3, h4 { font-weight: 600; line-height: 1.3; }

/* ==========================================================================
   App Shell Layout (sidebar + main)
   ========================================================================== */

.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */

.sidebar {
    width: 220px;
    flex-shrink: 0;
    background: #2c3e50;
    color: #ecf0f1;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    padding: 1.125rem 1.125rem;
    font-size: 1.0625rem;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid #34495e;
    letter-spacing: 0.01em;
    flex-shrink: 0;
}

.sidebar-brand small {
    display: block;
    font-size: 0.6875rem;
    font-weight: 400;
    color: #7f8c8d;
    margin-top: 1px;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.sidebar-nav {
    flex: 1;
    list-style: none;
    padding: 0.5rem 0;
}

.sidebar-nav li.nav-section {
    padding: 0.875rem 1.125rem 0.25rem;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: #566778;
    pointer-events: none;
}

.sidebar-nav a {
    display: block;
    padding: 0.5625rem 1.125rem;
    color: #b2bec3;
    font-size: 0.875rem;
    transition: background 0.12s, color 0.12s;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: #34495e;
    color: #fff;
    text-decoration: none;
}

.sidebar-footer {
    padding: 0.875rem 1.125rem;
    border-top: 1px solid #34495e;
    font-size: 0.8125rem;
    color: #7f8c8d;
    flex-shrink: 0;
}

.sidebar-footer strong { color: #b2bec3; font-weight: 500; }
.sidebar-footer a { color: #7f8c8d; font-size: 0.75rem; }
.sidebar-footer a:hover { color: #fff; text-decoration: none; }

/* --- Main content --- */

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    background: #fff;
    border-bottom: 1px solid #dfe6e9;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-title {
    flex: 1;
    font-size: 1.0625rem;
    font-weight: 600;
    color: #2c3e50;
}

.content {
    padding: 1.5rem;
    flex: 1;
}

/* ==========================================================================
   Cards
   ========================================================================== */

.card {
    background: #fff;
    border: 1px solid #dfe6e9;
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 1.25rem;
}

.card-header {
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid #dfe6e9;
    background: #f8f9fb;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.card-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: #4A6B8A;
    flex: 1;
    margin: 0;
}

.card-body {
    padding: 1.25rem;
}

/* ==========================================================================
   Dashboard stat cards
   ========================================================================== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: #fff;
    border: 1px solid #dfe6e9;
    border-radius: 6px;
    padding: 1.25rem 1.375rem;
}

.stat-card .stat-label {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: #636e72;
    margin-bottom: 0.5rem;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: #2c3e50;
    line-height: 1;
}

.stat-card .stat-sub {
    font-size: 0.8125rem;
    color: #636e72;
    margin-top: 0.3rem;
}

/* ==========================================================================
   Tables
   ========================================================================== */

.table-responsive { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

thead th {
    background: #34495e;
    color: #fff;
    padding: 0.625rem 0.875rem;
    font-weight: 600;
    text-align: left;
    font-size: 0.8125rem;
    white-space: nowrap;
    letter-spacing: 0.01em;
}

thead th.text-right { text-align: right; }
thead th.text-center { text-align: center; }

tbody tr { border-bottom: 1px solid #eaecef; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8f9fb; }
tbody tr:nth-child(even) { background: #fafbfc; }
tbody tr:nth-child(even):hover { background: #f0f4f8; }

tbody td {
    padding: 0.625rem 0.875rem;
    vertical-align: middle;
}

tbody td.text-right { text-align: right; }
tbody td.text-center { text-align: center; }
tbody td.text-muted { color: #636e72; font-size: 0.8125rem; }
tbody td.nowrap { white-space: nowrap; }

/* ==========================================================================
   Status Badges
   ========================================================================== */

.badge {
    display: inline-block;
    padding: 0.2em 0.55em;
    font-size: 0.7rem;
    font-weight: 700;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.badge-draft   { background: #e9ecef; color: #495057; }
.badge-sent    { background: #d6eaf8; color: #1a5276; }
.badge-paid    { background: #d5f5e3; color: #1e8449; }
.badge-partial { background: #fef9e7; color: #7d6608; border: 1px solid #f9e79f; }
.badge-overdue { background: #fadbd8; color: #922b21; }
.badge-void    { background: #e9ecef; color: #7f8c8d; text-decoration: line-through; }

/* ==========================================================================
   Forms
   ========================================================================== */

.form-group { margin-bottom: 1rem; }

label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: #4a4a4a;
    margin-bottom: 0.3125rem;
}

label.required::after {
    content: ' *';
    color: #e74c3c;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="tel"],
input[type="search"],
select,
textarea {
    display: block;
    width: 100%;
    padding: 0.4375rem 0.75rem;
    font-size: 0.9rem;
    font-family: inherit;
    line-height: 1.5;
    color: #333;
    background: #fff;
    border: 1px solid #ced4da;
    border-radius: 4px;
    transition: border-color 0.15s, box-shadow 0.15s;
    appearance: none;
    -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #4A6B8A;
    box-shadow: 0 0 0 3px rgba(74, 107, 138, 0.18);
}

input[readonly], input[disabled], select[disabled], textarea[readonly] {
    background: #f8f9fa;
    color: #636e72;
    cursor: default;
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236c757d'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.25rem;
}

textarea { resize: vertical; min-height: 80px; }

.form-text {
    font-size: 0.8125rem;
    color: #636e72;
    margin-top: 0.25rem;
}

.form-row   { display: grid; gap: 1rem; }
.form-col-2 { grid-template-columns: 1fr 1fr; }
.form-col-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-col-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.form-check input[type="checkbox"],
.form-check input[type="radio"] {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: #4A6B8A;
}

.form-check label {
    margin: 0;
    font-weight: 400;
    cursor: pointer;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4375rem 0.9375rem;
    font-size: 0.875rem;
    font-family: inherit;
    font-weight: 500;
    line-height: 1.5;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
    text-decoration: none;
    white-space: nowrap;
    vertical-align: middle;
}

.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.65; cursor: not-allowed; }

.btn-primary   { background: #4A6B8A; border-color: #4A6B8A; color: #fff; }
.btn-primary:hover { background: #3a5872; border-color: #3a5872; color: #fff; }

.btn-secondary { background: #636e72; border-color: #636e72; color: #fff; }
.btn-secondary:hover { background: #4d5557; border-color: #4d5557; color: #fff; }

.btn-success   { background: #27ae60; border-color: #27ae60; color: #fff; }
.btn-success:hover { background: #1e8449; border-color: #1e8449; color: #fff; }

.btn-danger    { background: #e74c3c; border-color: #e74c3c; color: #fff; }
.btn-danger:hover { background: #c0392b; border-color: #c0392b; color: #fff; }

.btn-warning   { background: #f39c12; border-color: #f39c12; color: #fff; }
.btn-warning:hover { background: #d68910; border-color: #d68910; color: #fff; }

.btn-outline   { background: transparent; border-color: #ced4da; color: #495057; }
.btn-outline:hover { background: #f8f9fa; border-color: #adb5bd; color: #333; }

.btn-sm {
    padding: 0.25rem 0.625rem;
    font-size: 0.8125rem;
}

.btn-lg {
    padding: 0.625rem 1.25rem;
    font-size: 1rem;
}

.btn-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

/* ==========================================================================
   Alerts / Flash messages
   ========================================================================== */

.alert {
    padding: 0.875rem 1.125rem;
    border-radius: 5px;
    border: 1px solid transparent;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert-success { background: #d5f5e3; border-color: #a9dfbf; color: #1e8449; }
.alert-error   { background: #fadbd8; border-color: #f1948a; color: #922b21; }
.alert-info    { background: #d6eaf8; border-color: #85c1e9; color: #1a5276; }
.alert-warning { background: #fef9e7; border-color: #f9e79f; color: #7d6608; }

/* ==========================================================================
   Filter / search bar
   ========================================================================== */

.filter-bar {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    flex-wrap: wrap;
}

.filter-bar input[type="search"],
.filter-bar input[type="text"],
.filter-bar select {
    width: auto;
    min-width: 160px;
}

/* ==========================================================================
   Pagination
   ========================================================================== */

.pagination {
    display: flex;
    gap: 0.25rem;
    list-style: none;
    margin-top: 1rem;
    justify-content: flex-end;
}

.pagination a,
.pagination span {
    display: block;
    padding: 0.3rem 0.7rem;
    font-size: 0.875rem;
    border: 1px solid #dfe6e9;
    border-radius: 4px;
    color: #4A6B8A;
    line-height: 1.5;
}

.pagination a:hover { background: #f0f4f8; text-decoration: none; }

.pagination .active span {
    background: #4A6B8A;
    border-color: #4A6B8A;
    color: #fff;
}

.pagination .disabled span { color: #adb5bd; }

/* ==========================================================================
   Login page (standalone, no sidebar)
   ========================================================================== */

.login-body {
    background: #f0f2f5;
}

.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.login-card {
    background: #fff;
    border: 1px solid #dfe6e9;
    border-radius: 8px;
    padding: 2.5rem 2.25rem;
    width: 100%;
    max-width: 390px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.07);
}

.login-card h1 {
    font-size: 1.375rem;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 0.2rem;
}

.login-card .login-sub {
    color: #636e72;
    font-size: 0.875rem;
    margin-bottom: 1.75rem;
}

/* ==========================================================================
   Invoice line-item editor (Phase 6)
   ========================================================================== */

.line-items-table thead th {
    background: #34495e;
    font-size: 0.75rem;
    padding: 0.5rem 0.625rem;
}

.line-items-table tbody td {
    padding: 0.375rem 0.375rem;
    vertical-align: top;
}

.line-items-table input,
.line-items-table select,
.line-items-table textarea {
    font-size: 0.875rem;
    padding: 0.3125rem 0.5rem;
}

.line-items-table textarea { min-height: 52px; }

.line-total-display {
    font-weight: 600;
    white-space: nowrap;
    padding-top: 0.5rem;
    display: block;
    text-align: right;
}

/* Totals block */
.totals-block {
    max-width: 320px;
    margin-left: auto;
    margin-top: 1rem;
}

.totals-block table { font-size: 0.9rem; }
.totals-block tbody td { padding: 0.3rem 0.5rem; border: none; }
.totals-block tbody td:first-child { color: #636e72; }
.totals-block tbody td:last-child { text-align: right; font-weight: 500; }
.totals-block .total-row td { font-size: 1.05rem; font-weight: 700; border-top: 2px solid #34495e; }
.totals-block .due-row td { font-size: 1.125rem; font-weight: 700; color: #2c3e50; }

/* ==========================================================================
   Invoice view / print template (web view)
   ========================================================================== */

.invoice-view {
    background: #fff;
    border: 1px solid #dfe6e9;
    border-radius: 6px;
    padding: 2.5rem;
    max-width: 820px;
}

.inv-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
}

.inv-logo img {
    max-height: 80px;
    max-width: 200px;
    object-fit: contain;
}

.inv-meta {
    text-align: right;
}

.inv-meta h1 {
    font-size: 1.5rem;
    color: #34495e;
    margin-bottom: 0.75rem;
}

.inv-meta-table { font-size: 0.875rem; margin-left: auto; }
.inv-meta-table td { padding: 0.15rem 0 0.15rem 1rem; }
.inv-meta-table td:first-child { color: #636e72; text-align: right; }
.inv-meta-table td:last-child { font-weight: 500; }

.inv-parties {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

.inv-party h2 {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: #4A6B8A;
    border-bottom: 1px solid #dfe6e9;
    padding-bottom: 0.375rem;
    margin-bottom: 0.625rem;
}

.inv-party strong { display: block; }
.inv-party p { font-size: 0.875rem; color: #555; line-height: 1.6; margin: 0; }

.inv-items-table thead th {
    background: #34495e;
    color: #fff;
    font-size: 0.75rem;
    padding: 0.5rem 0.75rem;
    text-align: right;
}

.inv-items-table thead th:first-child { text-align: left; }
.inv-items-table tbody td { padding: 0.75rem; font-size: 0.875rem; vertical-align: top; }
.inv-items-table tbody td:not(:first-child) { text-align: right; white-space: nowrap; }

.inv-product-name { font-weight: 600; }
.inv-product-desc { color: #636e72; font-size: 0.8125rem; margin-top: 2px; white-space: pre-line; }

.inv-totals {
    display: flex;
    justify-content: flex-end;
    align-items: flex-start;
    gap: 2rem;
    margin-top: 1.5rem;
}

.paid-stamp {
    border: 3px solid #7CB342;
    color: #7CB342;
    font-size: 1.5rem;
    font-weight: 700;
    padding: 0.5rem 1.25rem;
    letter-spacing: 0.1em;
    border-radius: 4px;
    align-self: center;
    opacity: 0.85;
    transform: rotate(-10deg);
    display: inline-block;
}

.inv-totals-table { font-size: 0.875rem; min-width: 240px; }
.inv-totals-table td { padding: 0.25rem 0.5rem; }
.inv-totals-table td:first-child { color: #636e72; }
.inv-totals-table td:last-child { text-align: right; font-weight: 500; min-width: 90px; }
.inv-totals-table .grand-total td { font-weight: 700; font-size: 1rem; border-top: 2px solid #34495e; padding-top: 0.4rem; }
.inv-totals-table .amount-due td { font-weight: 700; font-size: 1.125rem; color: #2c3e50; }

.inv-payment-details {
    margin-top: 2rem;
    padding-top: 1.25rem;
    border-top: 1px solid #dfe6e9;
}

.inv-payment-details h2 {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: #4A6B8A;
    border-bottom: 1px solid #dfe6e9;
    padding-bottom: 0.375rem;
    margin-bottom: 0.75rem;
}

.inv-payment-details p { font-size: 0.875rem; color: #555; margin-bottom: 0.5rem; }

.inv-bank-block { font-size: 0.875rem; margin-top: 0.5rem; }
.inv-bank-block dt { font-weight: 600; float: left; min-width: 130px; }
.inv-bank-block dd { margin-left: 130px; color: #333; }

.inv-footer {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid #eaecef;
    font-size: 0.8125rem;
    color: #636e72;
}

.no-gst-notice {
    font-style: italic;
    margin-top: 0.5rem;
}

/* ==========================================================================
   Utility classes
   ========================================================================== */

.text-muted   { color: #636e72; }
.text-right   { text-align: right; }
.text-center  { text-align: center; }
.text-danger  { color: #e74c3c; }
.text-success { color: #27ae60; }
.text-bold    { font-weight: 600; }
.text-small   { font-size: 0.8125rem; }

.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mt-1 { margin-top: 0.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-2 { margin-bottom: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-3 { margin-bottom: 1.5rem; }

.d-flex         { display: flex; }
.align-center   { align-items: center; }
.justify-between{ justify-content: space-between; }
.gap-1          { gap: 0.5rem; }
.gap-2          { gap: 1rem; }
.flex-1         { flex: 1; }
.w-100          { width: 100%; }

.hr { border: none; border-top: 1px solid #dfe6e9; margin: 1rem 0; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: #636e72;
}
.empty-state h3 {
    font-size: 1rem;
    color: #495057;
    margin-bottom: 0.375rem;
}

/* ==========================================================================
   Print styles (for @media print on the invoice view pages)
   ========================================================================== */

@media print {
    .sidebar,
    .topbar,
    .btn,
    .btn-group,
    .filter-bar,
    .no-print,
    .alert {
        display: none !important;
    }

    body {
        background: #fff;
        font-size: 11pt;
        color: #000;
    }

    .main-content { display: block; }
    .content { padding: 0; }

    .invoice-view {
        border: none;
        border-radius: 0;
        padding: 0;
        max-width: none;
    }

    .inv-items-table tbody tr:nth-child(even) { background: #f8f8f8; }

    a { color: inherit; }

    @page {
        margin: 15mm 15mm 20mm;
    }
}
