/* =====================================================================
   RAK Account Manager — theme
   Palette derived from the Website-11 logo:
     crimson #BF1E2E · orange #F7941E · olive #7C911C · ink #231F20
   Mapped deliberately, not arbitrarily: orange carries every primary
   action, crimson is danger/overdue (it already reads as "stop"),
   olive is success/paid (it already reads as "go").
   ===================================================================== */

:root {
    /* Brand */
    --brand-100: #FDECD6;
    --brand-200: #FBD9AE;
    --brand-300: #F7C17C;
    --brand-400: #F7941E;
    --brand-600: #DD7A0A;
    --brand-ink: #231F20;

    /* Neutrals */
    --gray-50:  #FAF9F8;
    --gray-100: #F1EFED;
    --gray-200: #E4E0DD;
    --gray-500: #7A7472;
    --gray-700: #453F3D;
    --gray-900: #231F20;

    /* Surfaces */
    --bg:      #F6F5F3;
    --surface: #FFFFFF;
    --surface-hover: #FAF9F8;
    --border:  #E4E0DD;

    /* Semantic (straight from the logo's own blocks) */
    --danger:  #BF1E2E;
    --danger-bg: #FBEAEA;
    --success: #6E8118;
    --success-bg: #EEF3DD;
    --warning: #92600A;
    --warning-bg: #FEF3E0;

    --radius: 10px;
    --shadow: 0 1px 3px rgba(35, 31, 32, 0.08), 0 1px 2px rgba(35, 31, 32, 0.04);

    --sidebar-width: 216px;
    --sidebar-collapsed-width: 64px;
    --topbar-height: 56px;

    color-scheme: light;
}

html[data-theme="dark"] {
    --brand-100: rgba(247, 148, 30, 0.16);
    --brand-200: rgba(247, 148, 30, 0.28);
    --brand-300: #C97A1F;
    --brand-400: #F7941E;
    --brand-600: #FFA43D;
    --brand-ink: #F5F3F1;

    --gray-50:  #211E20;
    --gray-100: #2A2628;
    --gray-200: #3B3638;
    --gray-500: #A79F9C;
    --gray-700: #D9D5D2;
    --gray-900: #F5F3F1;

    --bg:      #19171A;
    --surface: #221F22;
    --surface-hover: #2A2628;
    --border:  #3B3638;

    --danger:  #FF6B78;
    --danger-bg: rgba(255, 107, 120, 0.12);
    --success: #A8C13B;
    --success-bg: rgba(168, 193, 59, 0.14);
    --warning: #F0B93D;
    --warning-bg: rgba(240, 185, 61, 0.12);

    --shadow: 0 1px 3px rgba(0, 0, 0, 0.45), 0 1px 2px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--gray-900);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    transition: background-color 0.15s ease, color 0.15s ease;
}

a { color: var(--brand-600); }

/* ---------- Brand lockup (used in topbar + login) ---------- */

.brand-lockup { display: flex; align-items: center; gap: 10px; }
.brand-logo-chip {
    background: #fff;
    border-radius: 8px;
    padding: 5px 8px;
    display: inline-flex;
    align-items: center;
    box-shadow: 0 0 0 1px var(--border);
    flex-shrink: 0;
}
.brand-logo-chip img { display: block; height: 22px; width: auto; }
.brand-lockup-name { font-weight: 700; color: var(--brand-ink); font-size: 15px; letter-spacing: -0.01em; }
.brand-stripe { height: 3px; background: linear-gradient(90deg, var(--danger) 0 33%, var(--brand-400) 33% 66%, var(--success) 66% 100%); }

/* ---------- Login page (two-column, spec 4.1) ---------- */

.login-page { background: var(--bg); min-height: 100vh; }

.login-wrapper {
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    min-height: 100vh;
}

.login-wrapper-single { grid-template-columns: 1fr; }

.login-brand {
    background: linear-gradient(160deg, var(--brand-ink) 0%, #3a2f1f 55%, var(--brand-600) 130%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
    color: #fff;
}

.login-brand-inner { max-width: 420px; }

.login-brand .brand-logo-chip { padding: 10px 14px; border-radius: 12px; margin-bottom: 22px; box-shadow: none; }
.login-brand .brand-logo-chip img { height: 34px; }

.brand-name { font-size: 26px; font-weight: 700; margin: 0 0 8px; }
.brand-tagline { font-size: 15px; opacity: 0.85; margin: 0 0 32px; }
.brand-illustration svg { width: 100%; height: auto; }

.login-form-section {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    background: var(--surface);
}

.login-form-card { width: 100%; max-width: 360px; }
.login-heading { font-size: 22px; margin: 0 0 20px; color: var(--gray-900); }

.login-form { display: flex; flex-direction: column; gap: 6px; }
.login-form label { font-size: 13px; font-weight: 600; color: var(--gray-700); margin-top: 10px; }
.login-form input[type="text"],
.login-form input[type="email"],
.login-form input[type="password"] {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    background: var(--surface);
    color: var(--gray-900);
}
.login-form input:focus { outline: 2px solid var(--brand-300); border-color: var(--brand-400); }

.checkbox-row { display: flex; align-items: center; gap: 8px; font-weight: 400; font-size: 13px; color: var(--gray-700); }

.btn-primary {
    margin-top: 18px;
    padding: 11px 16px;
    background: var(--brand-400);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.12s ease;
}
.btn-primary:hover { background: var(--brand-600); }

.btn-link {
    background: none;
    border: none;
    color: var(--brand-600);
    font-size: 13px;
    cursor: pointer;
    padding: 10px 0;
    text-align: center;
    width: 100%;
}

.login-links { text-align: center; margin-top: 14px; font-size: 13px; }
.login-links a { color: var(--brand-600); text-decoration: none; }

.hidden { display: none !important; }

.alert {
    padding: 10px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 14px;
}
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.alert-info  { background: var(--brand-100); color: var(--brand-600); border: 1px solid var(--brand-200); }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid color-mix(in srgb, var(--success) 35%, transparent); }

@media (max-width: 768px) {
    .login-wrapper { grid-template-columns: 1fr; }
    .login-brand { display: none; } /* spec 4.1: mobile shows only the login form */
}

/* ---------- Authenticated app shell ---------- */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    height: var(--topbar-height);
    box-shadow: var(--shadow);
    gap: 16px;
    position: relative;
    z-index: 30;
}
.topbar-controls { display: flex; align-items: center; gap: 6px; }
.topbar-user { display: flex; align-items: center; gap: 14px; font-size: 14px; color: var(--gray-700); margin-left: auto; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--gray-700);
    cursor: pointer;
    flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--brand-600); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn span { display: inline-flex; align-items: center; justify-content: center; }
.sidebar-toggle-mobile { display: none; }

/* theme toggle: sun/moon swap by data-theme */
.theme-toggle .icon-moon { display: none; }
html[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: inline-flex; }

.app-shell { display: flex; min-height: calc(100vh - var(--topbar-height)); }

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 10px 0;
    display: flex;
    flex-direction: column;
    transition: width 0.15s ease;
    overflow-x: hidden;
}
.sidebar.collapsed { width: var(--sidebar-collapsed-width); }

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 18px;
    color: var(--gray-700);
    text-decoration: none;
    font-size: 13.5px;
    border-left: 3px solid transparent;
    white-space: nowrap;
}
.sidebar-link svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--gray-500); }
.sidebar-link:hover { background: var(--surface-hover); }
.sidebar-link:hover svg { color: var(--brand-600); }
.sidebar-link.active { color: var(--brand-600); border-left-color: var(--brand-400); background: var(--brand-100); font-weight: 600; }
.sidebar-link.active svg { color: var(--brand-600); }
.sidebar.collapsed .sidebar-link { justify-content: center; padding: 10px 0; gap: 0; }
.sidebar.collapsed .sidebar-label { display: none; }

.content { padding: 24px; flex: 1; min-width: 0; }

/* ---------- Page headers, toolbars, tables ---------- */

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 12px; }
.page-header h1 { font-size: 20px; margin: 0; color: var(--gray-900); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.toolbar input[type="text"], .toolbar select {
    padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; background: var(--surface); color: var(--gray-900);
}
.toolbar input[type="text"] { min-width: 220px; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; border: 1px solid var(--border); }

.data-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); font-size: 13px; border: 1px solid var(--border); }
.data-table th { text-align: left; background: var(--gray-50); color: var(--gray-500); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--gray-900); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface-hover); }
.data-table .empty-row td { text-align: center; color: var(--gray-500); padding: 30px; }

.row-actions { display: flex; gap: 8px; }
.row-actions a, .row-actions button { font-size: 12px; color: var(--brand-600); text-decoration: none; background: none; border: none; cursor: pointer; padding: 0; }
.row-actions .danger { color: var(--danger); }

.pagination { display: flex; gap: 6px; justify-content: flex-end; margin-top: 14px; }
.pagination a, .pagination span { padding: 6px 11px; border-radius: 6px; font-size: 13px; text-decoration: none; color: var(--gray-700); border: 1px solid var(--border); }
.pagination .active { background: var(--brand-400); color: #fff; border-color: var(--brand-400); }

/* ---------- Forms (create/edit pages) ---------- */

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-grid .full-width { grid-column: 1 / -1; }
.form-field label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-700); margin-bottom: 5px; }
.form-field input, .form-field select, .form-field textarea {
    width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; background: var(--surface); color: var(--gray-900); font-family: inherit;
}
.form-field .field-error { color: var(--danger); font-size: 12px; margin-top: 4px; }
.form-actions { margin-top: 22px; display: flex; gap: 10px; }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); border: 1px solid var(--border); padding: 10px 16px; border-radius: var(--radius); font-size: 14px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; }

/* ---------- Client/lead profile ---------- */

.profile-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.profile-header h1 { margin: 0 0 4px; font-size: 22px; color: var(--gray-900); }
.profile-meta { color: var(--gray-500); font-size: 13px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tab-link { padding: 10px 14px; font-size: 13px; color: var(--gray-500); text-decoration: none; border-bottom: 2px solid transparent; }
.tab-link.active { color: var(--brand-600); border-bottom-color: var(--brand-400); font-weight: 600; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-box { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; border: 1px solid var(--border); }
.stat-box .stat-label { font-size: 12px; color: var(--gray-500); }
.stat-box .stat-value { font-size: 22px; font-weight: 700; margin-top: 4px; color: var(--gray-900); }

/* ---------- Status badges ---------- */

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-normal   { background: var(--gray-100); color: var(--gray-700); }
.badge-info     { background: var(--brand-100); color: var(--brand-600); }
.badge-warning  { background: var(--warning-bg); color: var(--warning); }
.badge-urgent   { background: var(--warning-bg); color: var(--danger); }
.badge-critical { background: var(--danger-bg); color: var(--danger); }
.badge-success  { background: var(--success-bg); color: var(--success); }

/* ---------- Error pages ---------- */

.error-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.error-box { text-align: center; background: var(--surface); padding: 40px; border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); }
.error-box h1 { font-size: 48px; margin: 0 0 8px; color: var(--brand-600); }
.error-box a { color: var(--brand-600); }

@media (max-width: 900px) {
    .sidebar-toggle-mobile { display: inline-flex; }
    .sidebar-toggle-desktop { display: none; }
    .sidebar { position: fixed; left: calc(var(--sidebar-width) * -1); top: var(--topbar-height); bottom: 0; z-index: 20; transition: left 0.2s; box-shadow: var(--shadow); width: var(--sidebar-width) !important; }
    .sidebar.mobile-open { left: 0; }
    .sidebar.collapsed .sidebar-label { display: inline; }
    .sidebar.collapsed .sidebar-link { justify-content: flex-start; padding: 9px 18px; gap: 12px; }
    .form-grid { grid-template-columns: 1fr; }
    .brand-lockup-name { display: none; }
}
