:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface2: #f0f3f8;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: rgba(79, 70, 229, 0.1);
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #d97706;
    --radius: 10px;
    --sidebar-width: 260px;
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.1);
    --transition: 0.2s ease;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

body.sidebar-mobile-open { overflow: hidden; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 199;
    backdrop-filter: blur(2px);
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform var(--transition);
}

html[data-sidebar="open"] .sidebar {
    transform: translateX(0);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1rem;
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--text);
    border-bottom: 1px solid var(--border);
}

.sidebar-brand-text { letter-spacing: -0.02em; }

.sidebar-collapse { display: none; }

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0;
}

.nav-section {
    margin: 0.5rem 0.75rem;
    padding: 0.25rem 0 0.5rem;
    background: var(--surface2);
    border-radius: var(--radius);
    border-left: 3px solid var(--primary);
    overflow: hidden;
}

.nav-section-title {
    padding: 0.6rem 1rem 0.4rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.25rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.5rem 1rem;
    margin: 0.15rem 0.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: calc(var(--radius) - 2px);
    transition: background var(--transition), color var(--transition);
}

.nav-link:hover {
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
}

.nav-link.active {
    background: var(--primary-light);
    color: var(--primary);
}

.nav-icon {
    width: 1.1rem;
    text-align: center;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 0.75rem;
    border-top: 1px solid var(--border);
}

.sidebar-footer .nav-link {
    margin: 0;
    color: var(--text-muted);
}

.main-content {
    flex: 1;
    min-width: 0;
    width: 100%;
    margin-left: 0;
    transition: margin-left var(--transition), width var(--transition);
}

html[data-sidebar="open"] .main-content {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 50;
}

.page-header-start {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.page-header h1 {
    font-size: 1.35rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.sidebar-toggle { display: flex; }

.page-body { padding: 1.5rem; width: 100%; }

.user-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

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

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

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

.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; }

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.4rem;
    color: var(--text-muted);
    border-radius: calc(var(--radius) - 2px);
    transition: background var(--transition), color var(--transition);
}

.btn-icon:hover {
    color: var(--text);
    background: var(--surface2);
}

/* Cards & forms */
.card h3 { margin-bottom: 0.75rem; font-size: 1.05rem; }

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

.form-group label {
    display: block;
    margin-bottom: 0.3rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}

.form-group input:not([type="checkbox"]):not([type="radio"]),
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-check {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.form-check input[type="checkbox"] {
    width: auto;
    margin-top: 0.25rem;
    flex-shrink: 0;
    accent-color: var(--primary);
}

.form-check .form-check-text {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.form-check .form-check-text > span {
    color: var(--text);
    font-weight: 500;
}

.form-check .form-check-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 400;
}

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

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

.form-actions, .modal-actions, .page-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.inline-form { display: inline; }

/* Tables */
.table-wrap,
.data-table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    table-layout: auto;
}

.data-table th, .data-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}

.data-table th {
    background: var(--surface2);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface2); }
.data-table .actions { white-space: nowrap; }

.empty { color: var(--text-muted); padding: 2rem; text-align: center; }

.page-toolbar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.search-bar { margin-bottom: 1rem; }
.search-bar.hidden, .hidden { display: none !important; }

.search-bar input {
    padding: 0.5rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    width: 300px;
    font-family: inherit;
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    background: var(--surface2);
    color: var(--text-muted);
    font-weight: 500;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.6rem;
    background: var(--surface2);
    border-radius: 999px;
    font-size: 0.8rem;
    margin: 0.15rem;
}

.chip-remove { background: none; border: none; cursor: pointer; color: var(--text-muted); }

.location-chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
    padding: 0.35rem 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-height: 2.5rem;
}

.location-chips:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.location-chips-list {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.15rem;
}

.location-chips-input {
    flex: 1;
    min-width: 140px;
    width: auto !important;
    border: none !important;
    box-shadow: none !important;
    outline: none;
    padding: 0.25rem 0.35rem;
    background: transparent;
    font: inherit;
    color: var(--text);
}

.location-chip-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 0.15rem;
}

/* Modals */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(2px);
}

.modal-content {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
}

.modal-lg { max-width: 700px; }
.modal h3 { margin-bottom: 1rem; font-weight: 600; }

/* Auth */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-md);
}

.login-card h1 {
    margin-bottom: 1.5rem;
    text-align: center;
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert-error {
    background: rgba(220, 38, 38, 0.08);
    border: 1px solid rgba(220, 38, 38, 0.3);
    color: var(--danger);
}

.alert-success {
    background: rgba(22, 163, 74, 0.08);
    border: 1px solid rgba(22, 163, 74, 0.3);
    color: var(--success);
}

.staff-add-panel { margin-bottom: 1.25rem; }
.staff-add-panel .entity-form { margin-top: 1rem; }
.staff-manage > form { display: none; }

.staff-manage-table input:not([type="checkbox"]) {
    width: 100%;
    min-width: 5.5rem;
    padding: 0.4rem 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.85rem;
    font-family: inherit;
}

.staff-manage-table input[name="permission_level"] {
    min-width: 3.5rem;
    width: 4.5rem;
}

.staff-manage-table input[type="checkbox"] {
    width: auto;
    accent-color: var(--primary);
}

.staff-manage-table td { vertical-align: middle; }

/* Dashboard */
.dashboard-clock {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.clock-widget {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    width: 100%;
}

.shift-notes-box {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    white-space: pre-wrap;
    font-size: 0.9rem;
    margin: 0.75rem 0;
}

.shift-notes-cell {
    max-width: 280px;
    font-size: 0.85rem;
    white-space: pre-wrap;
}

.dashboard-actions {
    display: flex;
    gap: 0.75rem;
    margin: 1.25rem 0;
    flex-wrap: wrap;
}

.dashboard-tiles { display: grid; gap: 1.75rem; }

.tile-group h3 {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
}

.tile {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
    padding: 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
    box-shadow: var(--shadow-sm);
    transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.tile:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    text-decoration: none;
}

.tile-icon {
    font-size: 1.25rem;
    color: var(--primary);
    margin-bottom: 0.25rem;
}

.tile-label {
    font-weight: 500;
    font-size: 0.95rem;
}

.tile-count {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-top: auto;
}

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

/* Detail views */
.detail-view dl {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 0.5rem 1rem;
}

.detail-view dt { color: var(--text-muted); font-size: 0.85rem; }
.linked-items { margin: 1rem 0; }

.priority-low { color: var(--text-muted); }
.priority-medium { color: var(--primary); }
.priority-high { color: var(--warning); }
.priority-emergency { color: var(--danger); font-weight: 600; }

/* Notes */
.notes-accordion .note-item {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    overflow: hidden;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.note-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
    background: var(--surface);
}

.note-header:hover { background: var(--surface2); }
.note-preview { flex: 1; font-weight: 500; }
.note-meta { font-size: 0.8rem; color: var(--text-muted); }
.note-body { padding: 1rem; border-top: 1px solid var(--border); background: var(--bg); }
.note-attachments a { display: inline-block; margin-right: 0.5rem; font-size: 0.85rem; }

.filters-panel {
    background: var(--surface);
    padding: 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

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

.filters-form select,
.filters-form input[type="date"] {
    padding: 0.4rem 0.6rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: inherit;
}

.filters-inline-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Timeline */
.timeline-scroll {
    display: flex;
    align-items: stretch;
    gap: 0.5rem;
    overflow: hidden;
}

.timeline-days {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    flex: 1;
    scroll-behavior: smooth;
    padding: 0.5rem 0;
}

.timeline-day {
    min-width: 140px;
    min-height: 100px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}

.timeline-day:hover {
    border-color: var(--primary);
    background: var(--surface2);
}

.timeline-day.today { border-color: var(--primary); }

.timeline-day.selected {
    border-color: var(--primary);
    background: var(--primary-light);
    box-shadow: 0 0 0 2px var(--primary-light);
}

.timeline-day.selected.today {
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.25);
}
.day-label { font-weight: 600; }
.day-weekday { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.5rem; }

.timeline-entry {
    font-size: 0.75rem;
    padding: 0.3rem;
    margin-bottom: 0.25rem;
    background: var(--surface2);
    border-radius: 4px;
    border-left: 3px solid var(--primary);
    cursor: default;
}

.timeline-note-marker {
    font-size: 0.7rem;
    cursor: pointer;
    color: var(--warning);
    margin-top: 0.25rem;
}

.timeline-arrow {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 1.5rem;
    padding: 0.5rem;
    cursor: pointer;
    border-radius: var(--radius);
    flex-shrink: 0;
}

/* Whiteboard */
.whiteboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}

.whiteboard-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.whiteboard-card .card-link {
    display: block;
    padding: 1.25rem;
    color: var(--text);
    text-decoration: none;
}

.whiteboard-card .card-link:hover { background: var(--surface2); }
.card-meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.5rem; }
.card-actions { padding: 0.5rem; border-top: 1px solid var(--border); }

.whiteboard-toolbar-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.sync-status { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.5rem; }

/* Inquiries */
.inquiry-item {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.inquiry-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
}

.inquiry-header:hover { background: var(--surface2); }
.inquiry-body { padding: 1rem; border-top: 1px solid var(--border); }

.inquiry-body dl {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 0.4rem;
    font-size: 0.875rem;
}

.status-pill {
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    border: none;
    cursor: pointer;
    text-transform: capitalize;
    font-weight: 500;
}

.status-new { background: #dbeafe; color: #1d4ed8; }
.status-contacted { background: #fef3c7; color: #b45309; }
.status-in_progress { background: #dcfce7; color: #15803d; }
.status-closed { background: #fee2e2; color: #b91c1c; }

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

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

.stat-label { display: block; font-size: 0.75rem; color: var(--text-muted); font-weight: 500; }
.stat-value { font-size: 1.25rem; font-weight: 600; }

.view-toggle {
    display: inline-flex;
    gap: 0.25rem;
}

.view-toggle .btn { text-decoration: none; }

.view-toggle .btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Tools */
.tools-grid { display: flex; gap: 1rem; margin-top: 1rem; flex-wrap: wrap; }

.tool-tile {
    padding: 2rem 3rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1.1rem;
    text-decoration: none;
    box-shadow: var(--shadow-sm);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.tool-tile:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
    text-decoration: none;
}

.coming-soon { text-align: center; padding: 3rem; color: var(--text-muted); }
.skeleton-ui { max-width: 500px; margin: 2rem auto; text-align: left; }
.skeleton-field { margin-bottom: 1rem; }
.skeleton-field input, .skeleton-field textarea { width: 100%; opacity: 0.5; }

/* Profile */
.profile-avatar { margin-bottom: 1.5rem; }
.avatar-sm { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.avatar-lg { width: 80px; height: 80px; border-radius: 50%; object-fit: cover; }

.avatar-placeholder {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
    color: #fff;
}

.profile-section {
    margin: 1rem 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    background: var(--surface);
}

.profile-section summary { cursor: pointer; font-weight: 500; }

/* Permissions */
.permissions-matrix-wrap { overflow-x: auto; margin: 1rem 0; }
.permissions-matrix { border-collapse: collapse; font-size: 0.8rem; }

.permissions-matrix th, .permissions-matrix td {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    text-align: center;
}

.permissions-matrix .group-header td {
    background: var(--surface2);
    text-align: left;
    font-weight: 600;
}

.hint { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 1rem; }

/* Entity links */
.entity-links { margin: 1rem 0; }

.entity-link-fields { margin: 1rem 0; }

.entity-link-fields-label {
    display: block;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}

.entity-link-fields-grid {
    margin-bottom: 0;
}

.link-field-wrap {
    position: relative;
}

.link-field-wrap .link-search {
    width: 100%;
    padding-right: 2rem;
}

.link-field-wrap .link-clear {
    position: absolute;
    right: 0.25rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.25rem;
    line-height: 1;
}

.link-field .link-suggestions {
    top: 100%;
    left: 0;
    right: 0;
}
.link-add { display: flex; gap: 0.5rem; margin-top: 0.5rem; position: relative; }

.suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    z-index: 100;
    max-height: 200px;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
}

.suggestion-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.85rem;
}

.suggestion-item:hover { background: var(--surface2); }

/* RTE */
.rte-container {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
}

.rte-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    padding: 0.5rem;
    background: var(--surface2);
    border-bottom: 1px solid var(--border);
}

.rte-toolbar button {
    padding: 0.3rem 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    cursor: pointer;
    font-size: 0.8rem;
}

.rte-toolbar button:hover, .rte-toolbar button.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.rte-toolbar select, .rte-toolbar input[type=color] {
    padding: 0.2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
}

.rte-editor {
    min-height: 150px;
    padding: 0.75rem;
    background: var(--surface);
    outline: none;
}

.rte-full .rte-editor { min-height: 400px; }
.rte-size-small { font-size: 0.8em; }
.rte-size-normal { font-size: 1em; }
.rte-size-large { font-size: 1.25em; }
.rte-size-xlarge { font-size: 1.5em; }

.error-page { text-align: center; padding: 4rem; }
.error-page h1 { font-size: 4rem; color: var(--text-muted); }

.alert-warning {
    background: rgba(217, 119, 6, 0.1);
    border: 1px solid rgba(217, 119, 6, 0.35);
    color: var(--warning);
}

.ad-posts-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 0.5rem 0 1rem;
}

.ad-post-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.ad-post-card-header h2,
.ad-post-card-header h3 {
    margin: 0;
    font-size: 1.05rem;
}

.ad-post-remove:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.ad-media-preview { margin-bottom: 0.75rem; }

.ad-media-img,
.ad-media-video {
    display: block;
    width: 100%;
    max-height: 360px;
    object-fit: cover;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface2);
}

.ad-post-detail-grid {
    display: grid;
    grid-template-columns: minmax(180px, 280px) 1fr;
    gap: 1.25rem;
    align-items: start;
}

.ad-post-detail-grid dl {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 0.4rem 0.75rem;
    font-size: 0.9rem;
}

.ad-post-detail-grid dt { color: var(--text-muted); }

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

.perf-badge {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
}

.perf-average { background: #e2e8f0; color: #475569; }
.perf-good { background: #dbeafe; color: #1d4ed8; }
.perf-optimal { background: #dcfce7; color: #15803d; }

.share-url-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.share-url-row input {
    flex: 1;
    min-width: 180px;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.9rem;
}

body.public-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

.public-footer {
    padding: 1rem 1.5rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
}

.public-main {
    flex: 1;
    width: 100%;
    max-width: 920px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 2.5rem;
}

.public-report-heading {
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--primary);
    margin-bottom: 1.5rem;
}

.public-summary dl {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 0.4rem 0.75rem;
}

.public-summary dt { color: var(--text-muted); font-size: 0.85rem; }

.public-chart-heading {
    font-size: 1.05rem;
    margin-bottom: 1rem;
}

.public-chart-wrap {
    position: relative;
    height: 320px;
}

/* Ad Spend Tracker */
.ad-spend-page .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.ad-spend-page .detail-view.card {
    padding: 1.25rem;
}

.ad-spend-page .page-toolbar #toggle-filters {
    margin-left: auto;
}

.ad-spend-group-heading {
    margin: 0 0 1rem;
    font-size: 1.35rem;
}

.ad-spend-group-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.ad-spend-group-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
    color: inherit;
    flex-wrap: wrap;
}

.ad-spend-group-row:hover {
    background: var(--surface2);
    border-color: var(--border-strong, var(--border));
}

.ad-spend-group-row-main {
    flex: 1;
    min-width: 160px;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.ad-spend-accordion .ad-spend-item {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    overflow: hidden;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.ad-spend-header-row {
    display: flex;
    align-items: stretch;
    background: var(--surface);
}

.ad-spend-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
    background: var(--surface);
    flex-wrap: wrap;
    flex: 1;
    min-width: 0;
}

.ad-spend-header:hover { background: var(--surface2); }

.ad-spend-header-row:hover,
.ad-spend-header-row:hover .ad-spend-header {
    background: var(--surface2);
}

.ad-spend-header-main {
    flex: 1;
    min-width: 160px;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.ad-spend-title { font-weight: 600; }

.ad-spend-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.6rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    align-items: center;
}

.ad-spend-header-totals {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}

.ad-spend-header-actions {
    display: flex;
    gap: 0.15rem;
    flex-shrink: 0;
    align-items: center;
    padding: 0.5rem 0.75rem 0.5rem 0;
}

.ad-spend-header-actions a.btn-icon { text-decoration: none; }

.ad-spend-body {
    padding: 1rem;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.ad-spend-starting {
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

.ad-spend-entries {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
}

.ad-spend-entries th,
.ad-spend-entries td {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

.ad-spend-entries th {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
}

.ad-spend-entries tr:last-child td { border-bottom: none; }
.ad-spend-entries .actions { white-space: nowrap; text-align: right; }

.ad-spend-entries-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.ad-spend-entries-header h3 { margin-bottom: 0; }

.ad-spend-platforms {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1.25rem;
}

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

.ad-spend-group-field select { flex: 1; }

.ad-spend-filter-label {
    margin-bottom: 0.75rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.ad-spend-chart-wrap {
    position: relative;
    height: 320px;
}

.empty-inline {
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.stat-value.is-negative,
.is-negative {
    color: var(--danger);
}

/* Desktop */
@media (min-width: 769px) {
    .sidebar-toggle { display: none; }
    html[data-sidebar="collapsed"] .sidebar-toggle { display: inline-flex; }
    .sidebar-collapse { display: inline-flex; }
    .sidebar-backdrop { display: none !important; }
}

/* Mobile */
@media (max-width: 768px) {
    html[data-sidebar="open"] .main-content {
        margin-left: 0;
        width: 100%;
    }

    .page-header {
        padding: 0.75rem 1rem;
        gap: 0.5rem;
    }

    .page-header-start {
        flex: 1;
        min-width: 0;
    }

    .page-header h1 {
        font-size: 1.1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .user-badge {
        flex-shrink: 0;
        max-width: 45%;
        font-size: 0.75rem;
    }

    .user-badge span {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .search-bar input { width: 100%; }

    .dashboard-actions .btn {
        flex: 1;
        justify-content: center;
        min-width: calc(50% - 0.375rem);
    }

    .tiles {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }

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

    .ad-post-detail-grid,
    .ad-post-detail-grid dl,
    .public-summary dl {
        grid-template-columns: 1fr;
    }

    .share-url-row { flex-direction: column; }

    .share-url-row .btn,
    .share-url-row input { width: 100%; }

    .ad-spend-header-totals {
        width: 100%;
        order: 3;
    }

    .ad-spend-chart-wrap { height: 240px; }

    .modal-content { width: 95%; }

    .tools-grid { flex-direction: column; }

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