/* =============================================
   GestAbonne v3 — Editorial Warm Minimalism
   ============================================= */

:root {
    --ink: #1a1a2e;
    --ink-light: #2d2d44;
    --ink-muted: #6b6b80;
    --paper: #faf8f5;
    --paper-warm: #f5f0ea;
    --paper-hover: #efe9e0;
    --cream: #e8e0d4;
    --terracotta: #c4653a;
    --terracotta-light: #e8865e;
    --terracotta-bg: rgba(196,101,58,0.08);
    --sage: #5a7a5e;
    --sage-bg: rgba(90,122,94,0.08);
    --ocean: #3a6b8c;
    --ocean-bg: rgba(58,107,140,0.08);
    --amber: #c49a3a;
    --amber-bg: rgba(196,154,58,0.08);
    --red: #b94a48;
    --red-bg: rgba(185,74,72,0.08);
    --white: #ffffff;
    --shadow-sm: 0 1px 3px rgba(26,26,46,0.06);
    --shadow-md: 0 4px 16px rgba(26,26,46,0.08);
    --shadow-lg: 0 8px 32px rgba(26,26,46,0.12);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --font-display: 'Instrument Serif', Georgia, serif;
    --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --sidebar-width: 260px;
    --transition: 0.2s cubic-bezier(0.4,0,0.2,1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body { font-family: var(--font-body); background: var(--paper); color: var(--ink); line-height: 1.6; }

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

/* ========== SIDEBAR ========== */
.sidebar {
    width: var(--sidebar-width); background: var(--ink); color: #fff;
    display: flex; flex-direction: column; position: fixed; top: 0; left: 0;
    height: 100vh; z-index: 100; transition: transform var(--transition);
}
.sidebar-header { padding: 1.5rem 1.25rem; border-bottom: 1px solid rgba(255,255,255,0.08); }
.app-logo { display: flex; align-items: center; gap: 0.75rem; }
.logo-icon { width: 40px; height: 40px; background: var(--terracotta); border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; font-size: 1.1rem; }
.logo-title { font-family: var(--font-display); font-size: 1.25rem; font-weight: 400; letter-spacing: 0.01em; }
.logo-version { font-size: 0.7rem; opacity: 0.4; margin-top: 0.1rem; }

.sidebar-nav { flex: 1; padding: 1rem 0.75rem; overflow-y: auto; }
.nav-item {
    display: flex; align-items: center; gap: 0.75rem; padding: 0.65rem 1rem;
    border-radius: var(--radius-sm); color: rgba(255,255,255,0.6); text-decoration: none;
    font-size: 0.88rem; font-weight: 500; transition: all var(--transition); margin-bottom: 2px;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,0.06); }
.nav-item.active { color: #fff; background: var(--terracotta); }
.nav-item i { width: 18px; text-align: center; font-size: 0.85rem; }
.nav-separator { height: 1px; background: rgba(255,255,255,0.08); margin: 0.75rem 0.5rem; }

.sidebar-footer { padding: 1rem 1.25rem; border-top: 1px solid rgba(255,255,255,0.08); display: flex; align-items: center; justify-content: space-between; }
.user-info { display: flex; align-items: center; gap: 0.6rem; }
.user-avatar { width: 32px; height: 32px; background: var(--terracotta); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 700; }
.user-name { font-size: 0.8rem; font-weight: 600; }
.user-role { font-size: 0.68rem; opacity: 0.5; text-transform: capitalize; }
.logout-btn { color: rgba(255,255,255,0.4); font-size: 1rem; text-decoration: none; transition: color var(--transition); }
.logout-btn:hover { color: var(--red); }

/* ========== MAIN ========== */
.main-content { flex: 1; margin-left: var(--sidebar-width); display: flex; flex-direction: column; min-height: 100vh; }
.top-bar {
    height: 60px; background: var(--white); border-bottom: 1px solid var(--cream);
    display: flex; align-items: center; padding: 0 2rem; gap: 1rem; position: sticky; top: 0; z-index: 50;
}
.sidebar-toggle { display: none; background: none; border: none; font-size: 1.2rem; color: var(--ink); cursor: pointer; }
.page-title { font-family: var(--font-display); font-size: 1.4rem; font-weight: 400; color: var(--ink); }
.top-date { margin-left: auto; font-size: 0.8rem; color: var(--ink-muted); }
.top-date i { margin-right: 0.3rem; }

.content-area { padding: 2rem; flex: 1; }

/* ========== ALERTS ========== */
.alert {
    display: flex; align-items: center; gap: 0.75rem; padding: 0.85rem 1.25rem;
    border-radius: var(--radius-md); margin: 1rem 2rem 0; font-size: 0.88rem; animation: slideDown 0.3s ease;
}
.alert-success { background: var(--sage-bg); color: var(--sage); border: 1px solid rgba(90,122,94,0.15); }
.alert-error { background: var(--red-bg); color: var(--red); border: 1px solid rgba(185,74,72,0.15); }
.alert-info { background: var(--ocean-bg); color: var(--ocean); border: 1px solid rgba(58,107,140,0.15); }
.alert-close { background: none; border: none; cursor: pointer; color: inherit; opacity: 0.6; margin-left: auto; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* ========== CARDS ========== */
.card {
    background: var(--white); border-radius: var(--radius-lg); border: 1px solid var(--cream);
    box-shadow: var(--shadow-sm); overflow: hidden;
}
.card-header {
    padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--cream);
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.card-header h2 { font-family: var(--font-display); font-size: 1.15rem; font-weight: 400; }
.card-body { padding: 1.5rem; }

/* ========== STAT CARDS ========== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.25rem; margin-bottom: 2rem; }
.stat-card {
    background: var(--white); border-radius: var(--radius-lg); padding: 1.5rem;
    border: 1px solid var(--cream); box-shadow: var(--shadow-sm); transition: all var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-muted); font-weight: 600; margin-bottom: 0.5rem; }
.stat-value { font-family: var(--font-display); font-size: 2rem; font-weight: 400; color: var(--ink); line-height: 1.1; }
.stat-value.terracotta { color: var(--terracotta); }
.stat-value.sage { color: var(--sage); }
.stat-value.ocean { color: var(--ocean); }
.stat-value.amber { color: var(--amber); }
.stat-change { font-size: 0.75rem; margin-top: 0.4rem; display: flex; align-items: center; gap: 0.3rem; }
.stat-change.up { color: var(--sage); }
.stat-change.down { color: var(--red); }

/* ========== TABLES ========== */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
    text-align: left; padding: 0.75rem 1rem; font-size: 0.72rem; text-transform: uppercase;
    letter-spacing: 0.06em; color: var(--ink-muted); font-weight: 600; border-bottom: 2px solid var(--cream);
    background: var(--paper); white-space: nowrap;
}
tbody td { padding: 0.75rem 1rem; border-bottom: 1px solid rgba(232,224,212,0.5); font-size: 0.88rem; vertical-align: middle; }
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--paper-warm); }

/* ========== BADGES ========== */
.badge {
    display: inline-flex; align-items: center; padding: 0.25rem 0.65rem; border-radius: 999px;
    font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em;
}
.badge-success { background: var(--sage-bg); color: var(--sage); }
.badge-warning { background: var(--amber-bg); color: var(--amber); }
.badge-danger { background: var(--red-bg); color: var(--red); }
.badge-info { background: var(--ocean-bg); color: var(--ocean); }
.badge-muted { background: var(--paper-warm); color: var(--ink-muted); }
.badge-default { background: var(--paper-warm); color: var(--ink-muted); }

/* ========== BUTTONS ========== */
.btn {
    display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.6rem 1.2rem;
    border-radius: var(--radius-sm); font-family: var(--font-body); font-size: 0.85rem;
    font-weight: 600; border: none; cursor: pointer; text-decoration: none; transition: all var(--transition);
}
.btn-primary { background: var(--terracotta); color: #fff; }
.btn-primary:hover { background: var(--terracotta-light); }
.btn-secondary { background: var(--paper-warm); color: var(--ink); border: 1px solid var(--cream); }
.btn-secondary:hover { background: var(--paper-hover); }
.btn-danger { background: var(--red-bg); color: var(--red); }
.btn-danger:hover { background: rgba(185,74,72,0.15); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.78rem; }
.btn-icon { width: 32px; height: 32px; padding: 0; justify-content: center; border-radius: var(--radius-sm); }

/* ========== FORMS ========== */
.form-group { margin-bottom: 1.25rem; }
.form-group label {
    display: block; font-size: 0.78rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.04em; margin-bottom: 0.4rem; color: var(--ink);
}
.form-control {
    width: 100%; padding: 0.65rem 0.85rem; border: 1px solid var(--cream);
    border-radius: var(--radius-sm); font-family: var(--font-body); font-size: 0.9rem;
    background: var(--white); color: var(--ink); transition: all var(--transition);
}
.form-control:focus { outline: none; border-color: var(--terracotta); box-shadow: 0 0 0 3px var(--terracotta-bg); }
select.form-control { cursor: pointer; }
textarea.form-control { min-height: 80px; resize: vertical; }

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.form-hint { font-size: 0.75rem; color: var(--ink-muted); margin-top: 0.3rem; }

/* ========== TOOLBAR ========== */
.toolbar {
    display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1.5rem; flex-wrap: wrap;
}
.toolbar-search {
    flex: 1; min-width: 200px; position: relative;
}
.toolbar-search input {
    width: 100%; padding: 0.6rem 0.85rem 0.6rem 2.5rem; border: 1px solid var(--cream);
    border-radius: var(--radius-sm); font-family: var(--font-body); font-size: 0.88rem; background: var(--white);
}
.toolbar-search input:focus { outline: none; border-color: var(--terracotta); box-shadow: 0 0 0 3px var(--terracotta-bg); }
.toolbar-search i { position: absolute; left: 0.85rem; top: 50%; transform: translateY(-50%); color: var(--ink-muted); font-size: 0.85rem; }
.toolbar-filter select {
    padding: 0.6rem 0.85rem; border: 1px solid var(--cream); border-radius: var(--radius-sm);
    font-family: var(--font-body); font-size: 0.85rem; background: var(--white); cursor: pointer;
}

/* ========== TABS ========== */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--cream); margin-bottom: 1.5rem; }
.tab-btn {
    padding: 0.75rem 1.5rem; font-size: 0.85rem; font-weight: 600; color: var(--ink-muted);
    background: none; border: none; cursor: pointer; border-bottom: 2px solid transparent;
    margin-bottom: -2px; transition: all var(--transition); white-space: nowrap;
}
.tab-btn:hover { color: var(--ink); }
.tab-btn.active { color: var(--terracotta); border-bottom-color: var(--terracotta); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ========== PAGINATION ========== */
.pagination { display: flex; gap: 0.35rem; justify-content: center; margin-top: 1.5rem; }
.page-link {
    padding: 0.45rem 0.85rem; border: 1px solid var(--cream); border-radius: var(--radius-sm);
    font-size: 0.82rem; color: var(--ink); text-decoration: none; transition: all var(--transition);
}
.page-link:hover { background: var(--paper-warm); }
.page-link.active { background: var(--terracotta); color: #fff; border-color: var(--terracotta); }

/* ========== MODAL ========== */
.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(26,26,46,0.4); backdrop-filter: blur(4px); z-index: 200;
    align-items: center; justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--white); border-radius: var(--radius-lg); width: 90%; max-width: 600px;
    max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); animation: modalIn 0.25s ease;
}
.modal-header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--cream); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-family: var(--font-display); font-size: 1.15rem; }
.modal-close { background: none; border: none; font-size: 1.2rem; color: var(--ink-muted); cursor: pointer; }
.modal-body { padding: 1.5rem; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--cream); display: flex; gap: 0.75rem; justify-content: flex-end; }
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }

/* ========== EMPTY STATE ========== */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--ink-muted); }
.empty-state i { font-size: 2.5rem; margin-bottom: 0.75rem; opacity: 0.3; }
.empty-state p { font-size: 0.9rem; }

/* ========== RGPD ========== */
.rgpd-section { background: var(--ocean-bg); border: 1px solid rgba(58,107,140,0.15); border-radius: var(--radius-md); padding: 1.25rem; margin-top: 1.5rem; }
.rgpd-section h4 { color: var(--ocean); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.75rem; }
.rgpd-checkbox { display: flex; align-items: flex-start; gap: 0.5rem; margin-bottom: 0.5rem; font-size: 0.85rem; }
.rgpd-checkbox input[type="checkbox"] { margin-top: 0.2rem; accent-color: var(--ocean); }

/* ========== DASHBOARD GRID ========== */
.dashboard-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 1.5rem; margin-top: 1.5rem; }
.dashboard-full { grid-column: 1 / -1; }

/* ========== CHART PLACEHOLDER ========== */
.chart-bar { display: flex; align-items: flex-end; gap: 6px; height: 180px; padding-top: 1rem; }
.chart-bar-item {
    flex: 1; border-radius: 4px 4px 0 0; min-height: 4px;
    transition: all var(--transition); position: relative; cursor: default;
}
.chart-bar-item:hover { opacity: 0.8; }
.chart-bar-item .chart-tooltip {
    display: none; position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
    background: var(--ink); color: #fff; padding: 0.3rem 0.6rem; border-radius: 4px; font-size: 0.72rem; white-space: nowrap;
}
.chart-bar-item:hover .chart-tooltip { display: block; }
.chart-labels { display: flex; gap: 6px; margin-top: 0.5rem; }
.chart-labels span { flex: 1; text-align: center; font-size: 0.65rem; color: var(--ink-muted); }

/* ========== URGENCY ========== */
.urgency-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 0.4rem; }
.urgency-critical { background: var(--red); }
.urgency-high { background: #e67e22; }
.urgency-medium { background: var(--amber); }
.urgency-low { background: var(--ocean); }

/* ========== ACTION LINKS ========== */
.actions { display: flex; gap: 0.3rem; }
.actions a, .actions button {
    width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm); color: var(--ink-muted); text-decoration: none;
    font-size: 0.8rem; transition: all var(--transition); border: none; background: none; cursor: pointer;
}
.actions a:hover, .actions button:hover { background: var(--paper-warm); color: var(--ink); }
.actions .delete:hover { background: var(--red-bg); color: var(--red); }

/* ========== PRINT ========== */
@media print {
    .sidebar, .top-bar, .toolbar, .actions, .pagination, .sidebar-toggle { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .content-area { padding: 0 !important; }
    body { background: #fff; }
}

/* ========== DETAIL PAGE ========== */
.detail-topbar {
    display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap;
}
.detail-badges { display: flex; gap: 0.4rem; }
.detail-ids {
    margin-left: auto; display: flex; gap: 1.25rem; font-size: 0.8rem; color: var(--ink-muted);
}
.detail-ids span { white-space: nowrap; }
.detail-section { margin-bottom: 1.25rem; }
.detail-separator {
    height: 1px; background: var(--cream); margin: 1.25rem 0;
}
.detail-save-bar {
    position: sticky; bottom: 0; background: var(--paper); border-top: 1px solid var(--cream);
    padding: 1rem 0; text-align: right; z-index: 30; margin-bottom: 1.5rem;
}
.btn-lg { padding: 0.75rem 2rem; font-size: 0.95rem; }

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

@media (max-width: 768px) {
    .form-grid-2, .form-grid-3, .form-grid-4 { grid-template-columns: 1fr; }
    .detail-ids { margin-left: 0; flex-wrap: wrap; }
    .detail-save-bar { position: static; }
}
@media (min-width: 769px) and (max-width: 1024px) {
    .form-grid-3 { grid-template-columns: 1fr 1fr; }
    .form-grid-4 { grid-template-columns: 1fr 1fr; }
}

/* ========== SETTINGS LAYOUT (2 columns) ========== */
.settings-layout { display: flex; gap: 1.5rem; min-height: 500px; }
.settings-menu {
    width: 240px; flex-shrink: 0; background: var(--white); border-radius: var(--radius-lg);
    border: 1px solid var(--cream); box-shadow: var(--shadow-sm); padding: 0.75rem;
    position: sticky; top: 80px; align-self: flex-start; max-height: calc(100vh - 120px); overflow-y: auto;
}
.settings-menu-section { margin-bottom: 0.5rem; }
.settings-menu-section:last-child { margin-bottom: 0; }
.settings-menu-title {
    font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-muted);
    font-weight: 700; padding: 0.6rem 0.75rem 0.35rem; margin-top: 0.25rem;
}
.settings-menu-section:first-child .settings-menu-title { margin-top: 0; }
.settings-menu-item {
    display: flex; align-items: center; gap: 0.6rem; padding: 0.55rem 0.75rem;
    border-radius: var(--radius-sm); color: var(--ink); text-decoration: none;
    font-size: 0.84rem; font-weight: 500; transition: all var(--transition); margin-bottom: 1px;
}
.settings-menu-item:hover { background: var(--paper-warm); }
.settings-menu-item.active { background: var(--terracotta); color: #fff; }
.settings-menu-item i { width: 16px; text-align: center; font-size: 0.78rem; opacity: 0.7; }
.settings-menu-item.active i { opacity: 1; }
.settings-content { flex: 1; min-width: 0; }

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: block; }
    .main-content { margin-left: 0; }
    .content-area { padding: 1rem; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar-search { min-width: auto; }
    .settings-layout { flex-direction: column; }
    .settings-menu { width: 100%; position: static; max-height: none; }
}
@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
}

/* ========== LOGIN (standalone) ========== */
.login-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--paper) 0%, var(--paper-warm) 100%);
}
.login-card {
    background: var(--white); border-radius: var(--radius-xl); padding: 2.5rem;
    width: 100%; max-width: 400px; box-shadow: var(--shadow-lg); border: 1px solid var(--cream);
}
.login-card h1 { font-family: var(--font-display); font-size: 1.8rem; text-align: center; margin-bottom: 0.3rem; }
.login-card h1 span { color: var(--terracotta); }
.login-card .subtitle { text-align: center; color: var(--ink-muted); font-size: 0.85rem; margin-bottom: 1.5rem; }
.login-error {
    background: var(--red-bg); color: var(--red); border: 1px solid rgba(185,74,72,0.15);
    padding: 0.65rem 1rem; border-radius: var(--radius-sm); font-size: 0.85rem;
    margin-bottom: 1rem; display: flex; align-items: center; gap: 0.5rem;
}
.login-card button { width: 100%; justify-content: center; }
