/* =============================================================
   Telnyx SMS — shared layout & theme
   Muted, professional palette: warm linen / stone / sage
   (per code_rules/frontend_layout.md)
   ============================================================= */

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
    /* Sidebar dimensions */
    --sidebar-w: 240px;
    --sidebar-w-collapsed: 60px;
    --mobile-topbar-h: 52px;

    /* Color palette — muted, warm, professional */
    --bg-main:           #f8f7f4;   /* soft warm white / linen */
    --bg-card:           #ffffff;
    --bg-sidebar:        #edebe6;   /* light stone */
    --bg-sidebar-end:    #e6e3de;   /* header/footer of sidebar */
    --border:            #ddd9d2;   /* subtle warm gray */

    --text-primary:      #3a3835;   /* warm near-black */
    --text-muted:        #8c8883;   /* warm medium gray */
    --text-brand:        #4a4745;   /* slightly lighter than primary */

    --accent:            #7a9e8c;   /* sage green */
    --accent-dark:       #628077;   /* darker sage for hover */

    --nav-hover:         #e3dfd8;   /* subtle hover fill */
    --nav-active-bg:     #d8d3cc;   /* active fill */
    --nav-active-text:   #2d2b28;   /* slightly darker text when active */

    --logout-text:       #9e6a6a;   /* dusty rose-red */
    --logout-hover-bg:   #f0e8e8;

    --danger:            #9e6a6a;
    --danger-dark:       #855757;

    --success-bg:        #e7efe9;
    --success-text:      #47604f;
    --error-bg:          #f0e8e8;
    --error-text:        #7d5252;

    --transition:        0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    background: var(--bg-main);
    color: var(--text-primary);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    min-height: 100vh;
}

/* ── Desktop Sidebar ───────────────────────────────────────── */

/* Outer shell — clips content when collapsed */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-w-collapsed);       /* default: collapsed */
    overflow: hidden;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    z-index: 100;
    transition: width var(--transition);
}

#sidebar.expanded {
    width: var(--sidebar-w);
}

/* Inner container — always full width so text stays in place;
   the outer shell clips it when narrow */
.sidebar-inner {
    width: var(--sidebar-w);
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* ── Sidebar header — sticky toggle + brand ─────────────────
   The header is NOT inside the scroll area, so the toggle
   button is always visible at the top regardless of scroll. */
.sidebar-header {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 52px;
    background: var(--bg-sidebar-end);
    border-bottom: 1px solid var(--border);
}

.sidebar-toggle-btn {
    flex-shrink: 0;
    width: 60px;           /* exactly matches collapsed width */
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
    border-radius: 0;
    transition: background 0.15s, color 0.15s;
}

.sidebar-toggle-btn:hover {
    background: var(--nav-hover);
    color: var(--accent);
}

.sidebar-brand {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-brand);
    white-space: nowrap;
    letter-spacing: 0.01em;
}

/* ── Sidebar body — independently scrollable ──────────────── */
.sidebar-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 0;
    /* Thin custom scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.sidebar-body::-webkit-scrollbar { width: 4px; }
.sidebar-body::-webkit-scrollbar-track { background: transparent; }
.sidebar-body::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

/* ── Sidebar footer — logout, always visible ─────────────── */
.sidebar-footer {
    flex-shrink: 0;
    background: var(--bg-sidebar-end);
    border-top: 1px solid var(--border);
    padding: 6px 0;
}

/* ── Nav items ────────────────────────────────────────────── */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    padding: 4px 0;
}

/* Padding math: left=18px + icon=24px + label-margin=18px = 60px
   so label starts exactly at the collapsed clip boundary         */
.sidebar-nav-item {
    display: flex;
    align-items: center;
    padding: 10px 12px 10px 18px;
    color: var(--text-primary);
    text-decoration: none;
    white-space: nowrap;
    border-radius: 6px;
    margin: 2px 6px;
    font-size: 0.875rem;
    transition: background 0.15s, color 0.15s;
}

.sidebar-nav-item:hover {
    background: var(--nav-hover);
    color: var(--text-primary);
    text-decoration: none;
}

.sidebar-nav-active {
    background: var(--nav-active-bg);
    color: var(--nav-active-text);
    font-weight: 500;
}

.sidebar-nav-active:hover {
    background: var(--nav-active-bg);
}

.sidebar-nav-icon {
    font-size: 1.05rem;
    min-width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-nav-label {
    margin-left: 18px;
    white-space: nowrap;
}

.sidebar-nav-logout {
    color: var(--logout-text);
}

.sidebar-nav-logout:hover {
    background: var(--logout-hover-bg);
    color: var(--logout-text);
}

.sidebar-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

/* ── Main content area ────────────────────────────────────── */
#mainContent {
    margin-left: var(--sidebar-w-collapsed);
    min-height: 100vh;
    padding: 28px 32px;
    transition: margin-left var(--transition);
    max-width: 1400px;
}

#mainContent.content-sidebar-expanded {
    margin-left: var(--sidebar-w);
}

/* ── Mobile top bar ───────────────────────────────────────── */
.mobile-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--mobile-topbar-h);
    background: var(--bg-sidebar-end);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px 0 16px;
    z-index: 200;
}

.mobile-brand {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-brand);
    text-decoration: none;
    display: flex;
    align-items: center;
}

.mobile-hamburger,
.mobile-close-btn {
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1.3rem;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s;
}

.mobile-hamburger:hover,
.mobile-close-btn:hover {
    background: var(--nav-hover);
}

/* ── Mobile overlay backdrop ──────────────────────────────── */
.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(40, 36, 30, 0.35);
    z-index: 250;
    opacity: 0;
    transition: opacity 0.28s ease;
}

.mobile-overlay.visible  { display: block; }
.mobile-overlay.opaque   { opacity: 1; }

/* ── Mobile slide-in drawer ───────────────────────────────── */
.mobile-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 270px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    z-index: 300;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-drawer.open {
    transform: translateX(0);
}

.mobile-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px 0 16px;
    height: var(--mobile-topbar-h);
    background: var(--bg-sidebar-end);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.mobile-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.mobile-drawer-footer {
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    padding: 6px 0;
}

.mobile-nav {
    display: flex;
    flex-direction: column;
    padding: 4px 0;
}

.mobile-nav-item {
    display: flex;
    align-items: center;
    padding: 11px 20px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.9rem;
    border-radius: 6px;
    margin: 2px 8px;
    transition: background 0.15s;
    white-space: nowrap;
}

.mobile-nav-item:hover {
    background: var(--nav-hover);
    color: var(--text-primary);
    text-decoration: none;
}

.mobile-nav-active {
    background: var(--nav-active-bg);
    font-weight: 500;
}

.mobile-nav-logout {
    color: var(--logout-text);
}

.mobile-nav-logout:hover {
    background: var(--logout-hover-bg);
    color: var(--logout-text);
}

.mobile-nav-icon {
    font-size: 1.05rem;
    min-width: 24px;
    text-align: center;
    flex-shrink: 0;
    margin-right: 14px;
}

/* ── Responsive breakpoints ───────────────────────────────── */
@media (max-width: 991.98px) {
    #sidebar {
        display: none !important;
    }

    #mainContent {
        margin-left: 0 !important;
        padding: 20px 16px;
        padding-top: calc(var(--mobile-topbar-h) + 20px);
    }
}

@media (min-width: 992px) {
    .mobile-topbar  { display: none !important; }
    .mobile-drawer  { display: none !important; }
    .mobile-overlay { display: none !important; }
}

/* =============================================================
   Shared page components (cards, forms, buttons, tables)
   ============================================================= */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: 0 1px 3px rgba(58, 56, 53, 0.05);
}

.card h2, .card h3 {
    margin-top: 0;
    color: var(--text-brand);
    font-weight: 600;
}

.card-flush {
    padding: 0;
    overflow: hidden;
}

.card-flush-header {
    background: var(--bg-sidebar);
    padding: 0.9rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.card-flush-header h3 {
    margin: 0;
    font-size: 1.05rem;
}

.page-subtitle {
    color: var(--text-muted);
    margin: 0.25rem 0 0 0;
}

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

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-brand);
}

input[type="text"],
input[type="tel"],
input[type="date"],
input[type="password"],
textarea,
select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 16px;   /* >=16px prevents iOS auto-zoom on focus */
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-card);
    box-sizing: border-box;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 0.15rem rgba(122, 158, 140, 0.25);
}

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

/* Inline search rows: stack on mobile, row on wider screens */
.search-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.search-form .form-group {
    flex: 1;
    margin-bottom: 0;
}

@media (min-width: 576px) {
    .search-form {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: flex-end;
    }
    .search-form .form-group {
        min-width: 200px;
    }
}

/* Two-row search variant (calls/messages): wide text inputs get their own
   row so the quick-fill buttons don't squeeze them; dates + submit sit on
   a compact second row. Stacks to a single column on mobile. */
.search-form-rows {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.search-row {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.search-row .form-group {
    flex: 1;
    margin-bottom: 0;
}

/* Compact row (dates + submit): the two date fields share one line even
   on mobile — half width each — and the submit button wraps below them */
.search-row-compact {
    flex-direction: row;
    flex-wrap: wrap;
}

.search-row-compact .form-group {
    min-width: 0;
}

.search-row-compact .btn {
    flex: 1 1 100%;
}

@media (min-width: 576px) {
    .search-row {
        flex-direction: row;
        align-items: flex-end;
    }
    /* Date inputs keep a fixed width instead of stretching across the row */
    .search-row-compact .form-group {
        flex: 0 1 220px;
    }
    .search-row-compact .btn {
        flex: 0 0 auto;
    }
}

/* Input with quick-fill buttons ("Last call in" / "Last sms in"):
   buttons wrap below the input on narrow screens, sit inline on wide ones */
.input-with-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.input-with-buttons input {
    flex: 1 1 100%;
}

.input-with-buttons .btn {
    flex: 0 0 auto;
    white-space: nowrap;
}

@media (min-width: 576px) {
    .input-with-buttons {
        flex-wrap: nowrap;
    }
    .input-with-buttons input {
        flex: 1 1 auto;
        min-width: 0;
    }
}

/* Multi-field grids (add-customer form) — mobile-first */
.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-top: 1rem;
}

@media (min-width: 576px) {
    .form-grid {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    }
}

.form-grid .form-group {
    margin-bottom: 0;
}

.form-actions {
    grid-column: 1 / -1;
    display: flex;
    gap: 1rem;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
    display: inline-block;
    padding: 10px 22px;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: background 0.15s;
}

.btn:disabled {
    background-color: #b0aba5;
    cursor: not-allowed;
}

.btn-primary {
    background-color: var(--accent);
    color: #fff;
}

.btn-primary:hover:not(:disabled),
.btn-primary:focus {
    background-color: var(--accent-dark);
    color: #fff;
}

.btn-primary:focus {
    box-shadow: 0 0 0 0.2rem rgba(122, 158, 140, 0.35);
}

.btn-danger {
    background-color: var(--danger);
    color: #fff;
    padding: 8px 16px;
    font-size: 0.875rem;
}

.btn-danger:hover:not(:disabled) {
    background-color: var(--danger-dark);
}

.btn-neutral {
    background-color: var(--nav-active-bg);
    color: var(--text-primary);
}

.btn-neutral:hover:not(:disabled) {
    background-color: var(--nav-hover);
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.875rem;
}

.btn-block {
    display: block;
    width: 100%;
}

/* ── Tables — scroll inside their own container on mobile ── */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

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

.records-table th,
.records-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.records-table td.wrap-cell {
    white-space: normal;
    min-width: 220px;
    max-width: 340px;
    word-wrap: break-word;
}

.records-table th {
    background-color: var(--bg-sidebar);
    font-weight: 600;
    color: var(--text-brand);
    font-size: 0.85rem;
}

.records-table tbody tr:hover {
    background-color: var(--bg-main);
}

/* Inputs used for inline editing inside table cells */
.cell-input {
    min-width: 110px;
    padding: 6px 8px;
    font-size: 0.875rem;
}

.cell-input-wide {
    min-width: 180px;
}

/* ── Date-range summary bar & pagination ──────────────────── */
.range-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 1.75rem;
    padding: 0.9rem 1.5rem;
    background: var(--success-bg);
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    color: var(--success-text);
}

.range-summary strong {
    color: var(--text-brand);
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 0.9rem 1rem;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* ── Status / feedback ────────────────────────────────────── */
.loading,
.no-records {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}

.message {
    margin-top: 1rem;
    padding: 10px 14px;
    border-radius: 6px;
    display: none;
}

.message.success {
    background-color: var(--success-bg);
    color: var(--success-text);
    border: 1px solid #cfe0d5;
}

.message.error {
    background-color: var(--error-bg);
    color: var(--error-text);
    border: 1px solid #e0cfcf;
}

.id-badge {
    display: inline-block;
    background-color: var(--accent);
    color: #fff;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* ── List items (customers / presms) ──────────────────────── */
.list-item {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.list-item:last-child {
    border-bottom: none;
}

.list-item:hover {
    background-color: var(--bg-main);
}

.list-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.item-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.field-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem 1rem;
}

@media (min-width: 576px) {
    .field-grid {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    }
    .field-grid .full-width {
        grid-column: 1 / -1;
    }
}

.field-label {
    display: block;
    font-weight: 600;
    color: var(--text-brand);
    font-size: 0.8rem;
    margin-bottom: 0.15rem;
}

.field-value {
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.5;
}

.field-value.empty {
    color: var(--text-muted);
    font-style: italic;
}
