/* ============================================
   Tatrelisse Invoices - Stylesheet
   Palette: Terracotta / Sable / Chaleureux
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,500;0,600;1,400&family=DM+Sans:ital,wght@0,300;0,400;0,500;0,600;1,300;1,400&display=swap');

:root {
    --sand-light: #FAF6F0;
    --sand: #F5EDE3;
    --sand-dark: #E8DDD0;
    --terracotta: #C4927A;
    --terracotta-hover: #B07E68;
    --terracotta-light: rgba(196, 146, 122, 0.12);
    --olive: #7A8B6F;
    --text: #3D3530;
    --text-soft: #7A6F66;
    --text-faint: #AEA49A;
    --warm-white: #FFFCF8;
    --danger: #C47A7A;
    --danger-light: rgba(196, 122, 122, 0.12);
    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --shadow-sm: 0 1px 3px rgba(61, 53, 48, 0.06);
    --shadow: 0 2px 8px rgba(61, 53, 48, 0.08);
    --shadow-lg: 0 4px 16px rgba(61, 53, 48, 0.1);
    --transition: 0.2s ease;
}

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

html {
    font-size: 15px;
}

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--text);
    background: var(--sand-light);
    line-height: 1.6;
    min-height: 100vh;
}

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

.sidebar {
    width: 250px;
    background: var(--sand);
    border-right: 1px solid var(--sand-dark);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--sand-dark);
    text-align: center;
}

.sidebar-logo {
    max-width: 140px;
    height: auto;
}

.sidebar-brand {
    font-family: 'Lora', serif;
    font-size: 1.2rem;
    color: var(--text);
    font-weight: 500;
    margin-top: 0.4rem;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.7rem 1.5rem;
    color: var(--text-soft);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 400;
    transition: all var(--transition);
    border-left: 3px solid transparent;
}

.nav-item:hover {
    color: var(--text);
    background: var(--terracotta-light);
}

.nav-item.active {
    color: var(--terracotta);
    background: var(--terracotta-light);
    border-left-color: var(--terracotta);
    font-weight: 500;
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.nav-separator {
    height: 1px;
    background: var(--sand-dark);
    margin: 0.8rem 1.5rem;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--sand-dark);
    font-size: 0.8rem;
    color: var(--text-faint);
}

.sidebar-user {
    font-weight: 500;
    color: var(--text-soft);
    margin-bottom: 0.3rem;
}

.main-content {
    flex: 1;
    margin-left: 250px;
    padding: 2rem;
    min-height: 100vh;
}

/* ---- Mobile menu toggle ---- */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--sand);
    border-bottom: 1px solid var(--sand-dark);
    z-index: 99;
    align-items: center;
    padding: 0 1rem;
    justify-content: space-between;
}

.mobile-header .sidebar-brand {
    font-size: 1rem;
}

.menu-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--text);
}

.menu-toggle svg {
    width: 24px;
    height: 24px;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 99;
}

/* ---- Page Header ---- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-title {
    font-family: 'Lora', serif;
    font-size: 1.6rem;
    font-weight: 500;
    color: var(--text);
}

.page-subtitle {
    font-size: 0.85rem;
    color: var(--text-soft);
    margin-top: 0.2rem;
}

/* ---- Cards ---- */
.card {
    background: var(--warm-white);
    border: 1px solid var(--sand-dark);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.8rem;
    border-bottom: 1px solid var(--sand-dark);
}

.card-title {
    font-family: 'Lora', serif;
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text);
}

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

.stat-card {
    background: var(--warm-white);
    border: 1px solid var(--sand-dark);
    border-radius: var(--radius-lg);
    padding: 1.2rem 1.5rem;
    box-shadow: var(--shadow-sm);
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.4rem;
}

.stat-value {
    font-family: 'Lora', serif;
    font-size: 1.8rem;
    font-weight: 500;
    color: var(--text);
}

.stat-value.terracotta {
    color: var(--terracotta);
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 1.2rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition);
    white-space: nowrap;
    line-height: 1.4;
}

.btn svg {
    width: 16px;
    height: 16px;
}

.btn-primary {
    background: var(--terracotta);
    color: var(--warm-white);
    border-color: var(--terracotta);
}

.btn-primary:hover {
    background: var(--terracotta-hover);
    border-color: var(--terracotta-hover);
}

.btn-secondary {
    background: transparent;
    color: var(--text);
    border-color: var(--sand-dark);
}

.btn-secondary:hover {
    background: var(--sand);
    border-color: var(--text-faint);
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border-color: var(--danger);
}

.btn-danger:hover {
    background: var(--danger-light);
}

.btn-sm {
    padding: 0.35rem 0.8rem;
    font-size: 0.8rem;
}

.btn-icon {
    padding: 0.4rem;
    border: none;
    background: none;
    color: var(--text-soft);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.btn-icon:hover {
    background: var(--sand);
    color: var(--terracotta);
}

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

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

.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-soft);
    margin-bottom: 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 0.6rem 0.9rem;
    background: var(--warm-white);
    border: 1px solid var(--sand-dark);
    border-radius: var(--radius);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.9rem;
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--terracotta);
    box-shadow: 0 0 0 3px var(--terracotta-light);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--text-faint);
}

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

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.form-hint {
    font-size: 0.75rem;
    color: var(--text-faint);
    margin-top: 0.2rem;
}

.form-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-checkbox input[type="checkbox"] {
    accent-color: var(--terracotta);
    width: 16px;
    height: 16px;
}

.form-actions {
    display: flex;
    gap: 0.8rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

/* ---- Tables ---- */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--sand-dark);
    background: var(--warm-white);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    text-align: left;
    font-weight: 500;
    padding: 0.7rem 1rem;
    background: var(--sand);
    border-bottom: 2px solid var(--sand-dark);
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-soft);
    white-space: nowrap;
}

tbody td {
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--sand-dark);
    font-size: 0.88rem;
    vertical-align: middle;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background: var(--sand-light);
}

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

.text-center {
    text-align: center;
}

.text-muted {
    color: var(--text-faint);
}

.text-soft {
    color: var(--text-soft);
}

/* ---- Badges ---- */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 50px;
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.badge-draft {
    background: rgba(174, 164, 154, 0.15);
    color: var(--text-faint);
}

.badge-sent {
    background: var(--terracotta-light);
    color: var(--terracotta);
}

.badge-paid,
.badge-accepted {
    background: rgba(122, 139, 111, 0.15);
    color: var(--olive);
}

.badge-cancelled,
.badge-refused {
    background: var(--danger-light);
    color: var(--danger);
}

/* ---- Tabs ---- */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--sand-dark);
    margin-bottom: 1.5rem;
}

.tab {
    padding: 0.7rem 1.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-soft);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all var(--transition);
}

.tab:hover {
    color: var(--text);
}

.tab.active {
    color: var(--terracotta);
    border-bottom-color: var(--terracotta);
}

/* ---- Filters ---- */
.filters {
    display: flex;
    gap: 0.8rem;
    margin-bottom: 1.2rem;
    flex-wrap: wrap;
    align-items: end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.filter-group label {
    font-size: 0.7rem;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.filter-group .form-input,
.filter-group .form-select {
    padding: 0.45rem 0.7rem;
    font-size: 0.82rem;
    min-width: 140px;
}

/* ---- Search ---- */
.search-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    max-width: 400px;
}

.search-bar .form-input {
    flex: 1;
}

/* ---- Pagination ---- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    margin-top: 1.5rem;
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 0.5rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    text-decoration: none;
    color: var(--text-soft);
    transition: all var(--transition);
}

.pagination a:hover {
    background: var(--sand);
    color: var(--text);
}

.pagination .active {
    background: var(--terracotta);
    color: var(--warm-white);
}

/* ---- Alerts ---- */
.alert {
    padding: 0.8rem 1.2rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.88rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.alert-success {
    background: rgba(122, 139, 111, 0.12);
    color: var(--olive);
    border: 1px solid rgba(122, 139, 111, 0.25);
}

.alert-error {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid rgba(196, 122, 122, 0.25);
}

.alert-info {
    background: var(--terracotta-light);
    color: var(--terracotta);
    border: 1px solid rgba(196, 146, 122, 0.25);
}

/* ---- Document Lines (dynamic form) ---- */
.lines-table {
    width: 100%;
    margin-bottom: 1rem;
}

.lines-table th {
    font-size: 0.72rem;
    padding: 0.5rem;
}

.lines-table td {
    padding: 0.4rem;
    vertical-align: top;
}

.lines-table .form-input,
.lines-table .form-select {
    padding: 0.4rem 0.6rem;
    font-size: 0.82rem;
}

.line-total {
    font-weight: 500;
    color: var(--text);
    padding-top: 0.7rem;
    text-align: right;
    white-space: nowrap;
}

.document-total {
    text-align: right;
    padding: 1rem 0;
    border-top: 2px solid var(--terracotta);
    margin-top: 0.5rem;
}

.document-total .total-label {
    font-size: 0.85rem;
    color: var(--text-soft);
}

.document-total .total-value {
    font-family: 'Lora', serif;
    font-size: 1.6rem;
    font-weight: 500;
    color: var(--text);
}

/* ---- Document Preview ---- */
.document-detail {
    max-width: 800px;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.detail-section h3 {
    font-family: 'Lora', serif;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 0.3rem 0;
    font-size: 0.88rem;
}

.detail-row .label {
    color: var(--text-soft);
}

.detail-row .value {
    font-weight: 500;
}

/* ---- Empty State ---- */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-faint);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h3 {
    font-family: 'Lora', serif;
    font-size: 1.2rem;
    color: var(--text-soft);
    margin-bottom: 0.5rem;
}

.empty-state p {
    font-size: 0.88rem;
    margin-bottom: 1rem;
}

/* ---- Login Page ---- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--sand-light);
}

.login-card {
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
    background: var(--warm-white);
    border: 1px solid var(--sand-dark);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.login-card .logo {
    max-width: 160px;
    height: auto;
    margin-bottom: 1.5rem;
}

.login-card h1 {
    font-family: 'Lora', serif;
    font-size: 1.5rem;
    font-weight: 500;
    margin-bottom: 0.3rem;
}

.login-card .subtitle {
    font-size: 0.85rem;
    color: var(--text-soft);
    margin-bottom: 1.5rem;
}

.login-card .form-group {
    text-align: left;
}

.login-card .btn-primary {
    width: 100%;
    padding: 0.75rem;
    font-size: 0.95rem;
    margin-top: 0.5rem;
}

/* ---- Error Page ---- */
.error-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    text-align: center;
}

.error-code {
    font-family: 'Lora', serif;
    font-size: 5rem;
    color: var(--terracotta);
    line-height: 1;
    margin-bottom: 0.5rem;
}

/* ---- Settings Grid ---- */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

/* ---- Utilities ---- */
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.open {
        display: block;
    }

    .mobile-header {
        display: flex;
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
        padding-top: calc(56px + 1rem);
    }

    .page-header {
        flex-direction: column;
        align-items: stretch;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .filters {
        flex-direction: column;
    }

    .filter-group .form-input,
    .filter-group .form-select {
        min-width: auto;
        width: 100%;
    }

    .tabs {
        overflow-x: auto;
    }

    .btn-group {
        width: 100%;
    }

    .btn-group .btn {
        flex: 1;
        justify-content: center;
    }

    /* Responsive table */
    .lines-table thead {
        display: none;
    }

    .lines-table tbody tr {
        display: block;
        border: 1px solid var(--sand-dark);
        border-radius: var(--radius);
        margin-bottom: 0.8rem;
        padding: 0.8rem;
        background: var(--warm-white);
    }

    .lines-table tbody td {
        display: block;
        padding: 0.3rem 0;
        border-bottom: none;
    }

    .lines-table tbody td::before {
        content: attr(data-label);
        font-size: 0.7rem;
        font-weight: 500;
        color: var(--text-faint);
        text-transform: uppercase;
        letter-spacing: 0.04em;
        display: block;
        margin-bottom: 0.15rem;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .search-bar {
        max-width: none;
    }

    html {
        font-size: 14px;
    }
}

/* ---- Print ---- */
@media print {
    .sidebar,
    .mobile-header,
    .page-header .btn,
    .form-actions,
    .pagination {
        display: none !important;
    }

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