/* =============================================
   SORT ORGANIZER PORTAL — DESIGN SYSTEM
   ============================================= */

:root {
    --blue: #2196F3;
    --blue-light: #E3F2FD;
    --blue-hover: #1976D2;
    --green: #E53935;
    --green-light: #FFEBEE;
    --orange: #F59E0B;
    --orange-light: #FFFBEB;
    --red: #EF4444;
    --red-light: #FEF2F2;
    --gray-50: #F8FAFC;
    --gray-100: #F1F5F9;
    --gray-200: #E2E8F0;
    --gray-400: #94A3B8;
    --gray-500: #64748B;
    --gray-700: #334155;
    --gray-900: #0F172A;
    --white: #FFFFFF;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
}

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

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

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

.sidebar {
    width: 260px;
    background: var(--white);
    border-right: 1px solid var(--gray-200);
    padding: 24px 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-logo { padding: 0 24px 24px; border-bottom: 1px solid var(--gray-200); margin-bottom: 16px; }
.sidebar-logo h1 { font-size: 20px; font-weight: 700; }
.sidebar-logo h1 span { color: var(--blue); }
.sidebar-logo p { font-size: 12px; color: var(--gray-500); margin-top: 2px; }

.sidebar-nav { flex: 1; }

.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 24px; cursor: pointer;
    color: var(--gray-500); font-size: 14px; font-weight: 500;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}

.nav-item:hover { background: var(--gray-50); color: var(--gray-700); }
.nav-item.active { color: var(--blue); background: var(--blue-light); border-left-color: var(--blue); }
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }
.nav-item.danger { color: var(--red); }
.nav-item.danger:hover { background: var(--red-light); color: var(--red); }

.nav-separator {
    height: 1px;
    background: var(--gray-200);
    margin: 8px 24px;
}

.sidebar-footer { padding: 16px 24px; border-top: 1px solid var(--gray-200); }
.sidebar-footer .org-info { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.sidebar-footer .org-avatar {
    width: 36px; height: 36px; border-radius: 8px;
    background: var(--blue-light); color: var(--blue);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 14px; flex-shrink: 0; overflow: hidden;
}
.sidebar-footer .org-avatar img { width: 100%; height: 100%; object-fit: cover; }
.sidebar-footer .org-name { font-size: 13px; font-weight: 600; color: var(--gray-700); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer .org-email { font-size: 11px; color: var(--gray-400); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { margin-left: 260px; flex: 1; padding: 32px; }

/* =============================================
   LOGIN & ONBOARDING
   ============================================= */
.login-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--blue-light) 0%, var(--white) 50%, var(--gray-50) 100%);
}

.login-card {
    background: var(--white); border-radius: 16px; padding: 48px 40px;
    width: 100%; max-width: 420px; box-shadow: var(--shadow-md); text-align: center;
}

.login-card .logo { font-size: 28px; font-weight: 800; margin-bottom: 8px; }
.login-card .logo span { color: var(--blue); }
.login-card .tagline { color: var(--gray-500); font-size: 14px; margin-bottom: 36px; }
.login-card h2 { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.login-card p.desc { color: var(--gray-500); font-size: 14px; margin-bottom: 28px; line-height: 1.6; }

.login-card .google-btn {
    display: inline-flex; align-items: center; gap: 12px;
    padding: 14px 28px; border-radius: 10px; font-size: 15px; font-weight: 600;
    cursor: pointer; border: 1px solid var(--gray-200);
    background: var(--white); color: var(--gray-700);
    transition: all 0.15s; width: 100%; justify-content: center;
}
.login-card .google-btn:hover { background: var(--gray-50); border-color: var(--gray-400); box-shadow: var(--shadow); }
.login-card .google-btn svg { width: 20px; height: 20px; flex-shrink: 0; }
.login-card .footer-text { margin-top: 24px; font-size: 12px; color: var(--gray-400); }

.onboarding-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 32px;
    background: linear-gradient(135deg, var(--blue-light) 0%, var(--white) 50%, var(--gray-50) 100%);
}

.onboarding-card { background: var(--white); border-radius: 16px; padding: 40px; width: 100%; max-width: 520px; box-shadow: var(--shadow-md); }
.onboarding-card h2 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.onboarding-card .subtitle { color: var(--gray-500); font-size: 14px; margin-bottom: 28px; }

/* =============================================
   PAGE HEADERS, STATS, CARDS
   ============================================= */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 28px; }
.page-header h2 { font-size: 24px; font-weight: 700; }
.page-header p { color: var(--gray-500); font-size: 14px; margin-top: 2px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 28px; }

.stat-card { background: var(--white); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stat-card .icon {
    width: 40px; height: 40px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center; margin-bottom: 12px;
}
.stat-card .icon.blue { background: var(--blue-light); color: var(--blue); }
.stat-card .icon.green { background: var(--green-light); color: var(--green); }
.stat-card .icon.orange { background: var(--orange-light); color: var(--orange); }
.stat-card .icon.red { background: var(--red-light); color: var(--red); }
.stat-card .number { font-size: 28px; font-weight: 700; }
.stat-card .label { color: var(--gray-500); font-size: 13px; margin-top: 2px; }

.card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 24px; }
.card-header { display: flex; justify-content: space-between; align-items: center; padding: 20px 24px; border-bottom: 1px solid var(--gray-100); }
.card-header h3 { font-size: 16px; font-weight: 600; }
.card-body { padding: 24px; }

/* =============================================
   BUTTONS
   ============================================= */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 10px 18px; border-radius: 8px; font-size: 14px; font-weight: 600;
    cursor: pointer; border: none; transition: all 0.15s;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--blue-hover); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); }
.btn-secondary:hover:not(:disabled) { background: var(--gray-200); }
.btn-danger { background: var(--red-light); color: var(--red); }
.btn-danger:hover:not(:disabled) { background: #FEE2E2; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* =============================================
   TABLES
   ============================================= */
table { width: 100%; border-collapse: collapse; }
th { padding: 10px 16px; text-align: left; font-size: 12px; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: 0.5px; background: var(--gray-50); }
td { padding: 14px 16px; border-top: 1px solid var(--gray-100); font-size: 14px; }
tr:hover td { background: var(--gray-50); }
.empty-row { text-align: center; padding: 40px 16px; color: var(--gray-400); }

/* =============================================
   TAGS
   ============================================= */
.tag { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 500; }
.tag-blue { background: var(--blue-light); color: var(--blue); }
.tag-green { background: var(--green-light); color: var(--green); }
.tag-orange { background: var(--orange-light); color: var(--orange); }

.amenity-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.amenity-chip { background: var(--gray-100); color: var(--gray-700); padding: 4px 10px; border-radius: 6px; font-size: 12px; }

/* =============================================
   MODALS
   ============================================= */
.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4); z-index: 1000;
    align-items: flex-start; justify-content: center;
    padding: 40px 20px; overflow-y: auto;
}
.modal-overlay.active { display: flex; }

.modal {
    background: var(--white); border-radius: 16px; padding: 32px;
    width: 100%; max-width: 700px; box-shadow: var(--shadow-md); margin: auto 0;
}
.modal h2 { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.modal .subtitle { color: var(--gray-500); font-size: 14px; margin-bottom: 24px; }

/* =============================================
   FORMS
   ============================================= */
.form-section { margin-bottom: 24px; }
.form-section-title {
    font-size: 13px; font-weight: 700; color: var(--gray-500);
    text-transform: uppercase; letter-spacing: 0.5px;
    margin-bottom: 14px; padding-bottom: 8px; border-bottom: 1px solid var(--gray-100);
}

.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-700); margin-bottom: 6px; }
.form-group input, .form-group textarea, .form-group select {
    width: 100%; padding: 10px 14px; border: 1px solid var(--gray-200); border-radius: 8px;
    font-size: 14px; font-family: inherit; transition: border-color 0.15s; background: var(--white);
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
    outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.form-group .hint { font-size: 12px; color: var(--gray-400); margin-top: 4px; }

.modal-actions { display: flex; gap: 12px; margin-top: 28px; }
.modal-actions .btn { flex: 1; justify-content: center; padding: 12px; }

/* =============================================
   AMENITY / TAG INPUT
   ============================================= */
.amenity-input-wrap { display: flex; gap: 8px; }
.amenity-input-wrap input { flex: 1; }
.amenity-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.amenity-tag {
    display: inline-flex; align-items: center; gap: 4px;
    background: var(--blue-light); color: var(--blue);
    padding: 4px 10px; border-radius: 6px; font-size: 13px;
}
.amenity-tag .remove { cursor: pointer; font-weight: 700; opacity: 0.6; }
.amenity-tag .remove:hover { opacity: 1; }

/* =============================================
   AGENDA BUILDER
   ============================================= */
.agenda-rows { margin-top: 8px; }
.agenda-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: flex-start; }
.agenda-row input:first-child { width: 110px; flex-shrink: 0; }
.agenda-row-fields { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.agenda-row-fields input, .agenda-row-fields textarea {
    width: 100%; padding: 8px 12px; border: 1px solid var(--gray-200);
    border-radius: 6px; font-size: 13px; font-family: inherit;
}
.agenda-row-fields input:focus, .agenda-row-fields textarea:focus { outline: none; border-color: var(--blue); }
.agenda-row-fields textarea { min-height: 40px; resize: vertical; }
.agenda-row input { padding: 8px 12px; border: 1px solid var(--gray-200); border-radius: 6px; font-size: 13px; font-family: inherit; }
.agenda-row input:focus { outline: none; border-color: var(--blue); }
.agenda-row .btn-remove {
    width: 32px; height: 32px; border-radius: 6px; border: none;
    background: var(--red-light); color: var(--red); cursor: pointer;
    font-size: 16px; display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: background 0.15s; margin-top: 2px;
}
.agenda-row .btn-remove:hover { background: #FEE2E2; }

/* =============================================
   CHECKBOX GRIDS
   ============================================= */
.checkbox-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.checkbox-item { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--gray-700); cursor: pointer; }
.checkbox-item input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--blue); cursor: pointer; }

.checkbox-group { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.checkbox-group input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--blue); }
.checkbox-group label { font-size: 14px; font-weight: 500; color: var(--gray-700); margin-bottom: 0; }

.recurrence-options { display: none; margin-top: 8px; }
.recurrence-options.visible { display: block; }

/* =============================================
   PROFILE PAGE
   ============================================= */
.profile-form { max-width: 640px; }
.profile-header { display: flex; align-items: center; gap: 20px; margin-bottom: 28px; }
.profile-avatar {
    width: 80px; height: 80px; border-radius: 16px;
    background: var(--blue-light); color: var(--blue);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 28px; flex-shrink: 0; overflow: hidden;
}
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* IMAGE PREVIEW */
.image-preview {
    margin-top: 8px; width: 100%; max-height: 160px; border-radius: 8px;
    object-fit: cover; display: none; border: 1px solid var(--gray-200);
}
.image-preview.visible { display: block; }

/* FILE UPLOAD AREA */
.upload-area {
    position: relative;
    border: 2px dashed var(--gray-200);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    overflow: hidden;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.upload-area:hover {
    border-color: var(--blue);
    background: var(--blue-light);
}
.upload-area.dragging {
    border-color: var(--blue);
    background: var(--blue-light);
}
.upload-area.has-image {
    border-style: solid;
    border-color: var(--gray-200);
    cursor: default;
}
.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 24px 16px;
    color: var(--gray-400);
    font-size: 14px;
    pointer-events: none;
}
.upload-placeholder svg {
    color: var(--gray-400);
}
.upload-hint {
    font-size: 12px;
    color: var(--gray-400);
}
.upload-area .image-preview {
    margin-top: 0;
    width: 100%;
    max-height: 200px;
    border-radius: 6px;
    object-fit: cover;
    border: none;
}
.upload-remove-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.6);
    color: white;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.upload-remove-btn:hover {
    background: rgba(0,0,0,0.8);
}
.upload-status {
    font-size: 12px;
    margin-top: 6px;
    min-height: 18px;
}
.upload-status.uploading { color: var(--blue); }
.upload-status.error { color: var(--red); }
.upload-status.success { color: var(--blue); }

/* =============================================
   PAGES
   ============================================= */
.page { display: none; }
.page.active { display: block; }

/* =============================================
   LOADING
   ============================================= */
.loading-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--gray-50); }
.spinner { width: 40px; height: 40px; border: 3px solid var(--gray-200); border-top-color: var(--blue); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { margin-top: 16px; font-size: 14px; color: var(--gray-500); }

/* =============================================
   TOAST
   ============================================= */
.toast {
    position: fixed; bottom: 24px; right: 24px;
    background: var(--gray-900); color: white;
    padding: 14px 20px; border-radius: 10px;
    font-size: 14px; font-weight: 500; z-index: 2000;
    transform: translateY(100px); opacity: 0; transition: all 0.3s; max-width: 400px;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }

/* =============================================
   VIEW CONTAINERS
   ============================================= */
#view-loading, #view-login, #view-onboarding, #view-app { display: none; }
#view-loading.active { display: block; }
#view-login.active { display: block; }
#view-onboarding.active { display: block; }
#view-app.active { display: block; }

/* =============================================
   TICKETS PAGE
   ============================================= */
.ticket-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.ticket-stat {
    background: var(--white);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
    box-shadow: var(--shadow);
}

.ticket-stat .number { font-size: 24px; font-weight: 700; }
.ticket-stat .label { font-size: 12px; color: var(--gray-500); margin-top: 2px; }

.ticket-filters {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.ticket-filter-btn {
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--gray-200);
    background: var(--white);
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-500);
    cursor: pointer;
    transition: all 0.15s;
}

.ticket-filter-btn:hover { background: var(--gray-50); }
.ticket-filter-btn.active { background: var(--blue); color: white; border-color: var(--blue); }

/* =============================================
   ANALYTICS PAGE
   ============================================= */
.stats-score-card {
    background: linear-gradient(135deg, var(--blue) 0%, #1565C0 100%);
    border-radius: var(--radius);
    padding: 28px;
    color: white;
    margin-bottom: 24px;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 28px;
    align-items: center;
}

.stats-score-number {
    font-size: 56px;
    font-weight: 800;
    line-height: 1;
}

.stats-score-label {
    font-size: 14px;
    opacity: 0.8;
    margin-top: 4px;
}

.stats-mini-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.stats-mini-stat {
    text-align: center;
}

.stats-mini-stat .number {
    font-size: 22px;
    font-weight: 700;
}

.stats-mini-stat .label {
    font-size: 12px;
    opacity: 0.7;
}

.stats-range-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.stats-range-btn {
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--gray-200);
    background: var(--white);
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-500);
    cursor: pointer;
    transition: all 0.15s;
}

.stats-range-btn:hover { background: var(--gray-50); }
.stats-range-btn.active { background: var(--blue); color: white; border-color: var(--blue); }

.stats-charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.chart-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.chart-card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-100);
    font-size: 15px;
    font-weight: 600;
}

.chart-card-body {
    padding: 20px;
    position: relative;
}

.chart-card-body.tall {
    height: 300px;
}

.chart-card.full-width {
    grid-column: 1 / -1;
}

/* =============================================
   CHATS PAGE
   ============================================= */
.chat-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 0;
    border-bottom: 2px solid var(--gray-200);
}

.chat-tab-btn {
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-500);
    background: none;
    border: none;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
}

.chat-tab-btn:hover { color: var(--gray-700); }
.chat-tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }

.chat-layout {
    display: flex;
    height: calc(100vh - 200px);
    min-height: 500px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--white);
}

.chat-list {
    width: 300px;
    border-right: 1px solid var(--gray-200);
    overflow-y: auto;
    flex-shrink: 0;
}

.chat-list-item {
    padding: 14px 16px;
    border-bottom: 1px solid var(--gray-100);
    cursor: pointer;
    transition: background 0.1s;
}

.chat-list-item:hover { background: var(--gray-50); }
.chat-list-item.active { background: var(--blue-light); border-left: 3px solid var(--blue); }

.chat-panel {
    flex: 1;
    display: none;
    flex-direction: column;
}

.chat-panel-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--gray-200);
    font-weight: 600;
    font-size: 15px;
    background: var(--gray-50);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.chat-input-bar {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
}

.chat-input-bar input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
}

.chat-input-bar input:focus {
    outline: none;
    border-color: var(--blue);
}

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 1024px) {
    .stats { grid-template-columns: repeat(2, 1fr); }
    .checkbox-grid { grid-template-columns: repeat(2, 1fr); }
    .stats-charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar { display: none; }
    .main { margin-left: 0; }
    .stats { grid-template-columns: 1fr; }
    .form-row, .form-row-3 { grid-template-columns: 1fr; }
    .checkbox-grid { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
    .chat-layout { flex-direction: column; height: auto; }
    .chat-list { width: 100%; border-right: none; border-bottom: 1px solid var(--gray-200); max-height: 200px; }
    .ticket-stats { grid-template-columns: 1fr; }
}
