/* ═══════════════════════════════════════════════════════
   D-Dey Admin — Apple-style Design System
   ═══════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800;900&display=swap');

:root {
    --bg: #F2F2F7;
    --surface: #FFFFFF;
    --surface2: #F2F2F7;
    --border: rgba(0,0,0,0.08);
    --text-primary: #1C1C1E;
    --text-secondary: #6B7280;
    --text-tertiary: #AEAEB2;
    --teal: #0D9488;
    --teal-light: #f0fdfa;
    --teal-dark: #0F766E;
    --purple: #6366F1;
    --purple-light: #EEF2FF;
    --danger: #EF4444;
    --danger-light: #FEF2F2;
    --warning: #F59E0B;
    --green: #22C55E;
    --green-light: #F0FDF4;
    --yellow: #EAB308;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
    --shadow-lg: 0 20px 60px rgba(0,0,0,0.15);
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --nav-h: 60px;
    --header-h: 56px;
}

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

html, body {
    height: 100%; width: 100%;
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

/* ── LOGIN ────────────────────────────────────────────── */
#login-screen {
    display: flex; align-items: center; justify-content: center;
    height: 100dvh; background: var(--bg);
    animation: fadeIn .4s ease;
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 40px 32px;
    width: min(380px, 90vw);
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.login-logo {
    width: 72px; height: 72px;
    border-radius: 20px;
    background: linear-gradient(135deg, #0D9488, #0EA5E9);
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 20px;
    box-shadow: 0 8px 24px rgba(13,148,136,.3);
}

.login-logo svg { width: 36px; height: 36px; }
.login-title { font-size: 1.5rem; font-weight: 800; color: var(--text-primary); margin-bottom: 4px; }
.login-sub { font-size: .85rem; color: var(--text-secondary); margin-bottom: 32px; }

.google-btn {
    width: 100%; padding: 14px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center; gap: 12px;
    font-size: .9rem; font-weight: 600; color: var(--text-primary);
    cursor: pointer; font-family: inherit;
    transition: all .15s;
}
.google-btn:hover { background: var(--bg); border-color: #d1d5db; }
.google-btn:active { transform: scale(.98); }

.login-error {
    margin-top: 12px; padding: 10px 14px;
    background: var(--danger-light); color: var(--danger);
    border-radius: var(--radius-sm); font-size: .82rem;
}

/* ── APP SHELL ────────────────────────────────────────── */
#app-screen {
    display: flex; flex-direction: column;
    height: 100dvh; overflow: hidden;
}

/* ── HEADER ───────────────────────────────────────────── */
.admin-header {
    height: var(--header-h);
    background: rgba(242,242,247,.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 16px; gap: 12px;
    flex-shrink: 0; z-index: 10;
}

.header-logo {
    width: 32px; height: 32px;
    border-radius: 9px;
    background: linear-gradient(135deg, #0D9488, #0EA5E9);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.header-logo svg { width: 16px; height: 16px; }

.header-title {
    font-size: .9rem; font-weight: 700; color: var(--text-primary);
    flex: 1;
}

#server-status-wrapper { display: flex; align-items: center; }

.server-toggle-wrap { display: flex; align-items: center; gap: 8px; }

.toggle-pill { position: relative; display: inline-flex; cursor: pointer; }
.toggle-pill input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-track {
    width: 44px; height: 26px;
    background: #d1d5db;
    border-radius: 100px;
    transition: background .2s;
    display: flex; align-items: center;
    padding: 0 3px;
}
.toggle-pill input:checked ~ .toggle-track { background: var(--teal); }

.toggle-thumb {
    width: 20px; height: 20px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 1px 4px rgba(0,0,0,.2);
    transition: transform .2s;
}
.toggle-pill input:checked ~ .toggle-track .toggle-thumb { transform: translateX(18px); }

.server-label { font-size: .75rem; font-weight: 600; }
.server-label.online { color: var(--teal); }
.server-label.offline { color: var(--danger); }

.header-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--teal);
    display: flex; align-items: center; justify-content: center;
    font-size: .8rem; font-weight: 700; color: white;
    overflow: hidden; cursor: pointer;
    flex-shrink: 0;
}
.header-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ── BOTTOM NAV ───────────────────────────────────────── */
.admin-nav {
    height: var(--nav-h);
    background: rgba(242,242,247,.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    display: flex; align-items: stretch;
    flex-shrink: 0;
}

.sa-tab-btn {
    flex: 1; background: none; border: none;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 3px; cursor: pointer;
    color: var(--text-tertiary);
    font-family: inherit; font-size: .62rem; font-weight: 600;
    transition: color .15s;
    position: relative;
}

.sa-tab-btn.active { color: var(--teal); }

.tab-icon {
    width: 24px; height: 24px;
    display: flex; align-items: center; justify-content: center;
}

.tab-badge {
    position: absolute; top: 6px; right: calc(50% - 18px);
    min-width: 17px; height: 17px;
    background: var(--danger);
    border-radius: 100px;
    font-size: .6rem; font-weight: 800; color: white;
    display: none; align-items: center; justify-content: center;
    padding: 0 4px;
    border: 2px solid var(--bg);
}

/* ── CONTENT ──────────────────────────────────────────── */
.admin-content {
    flex: 1; overflow-y: auto;
    padding: 16px;
    animation: fadeIn .2s ease;
}

/* ── CLIENT CARD ──────────────────────────────────────── */
.client-card {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-sm);
    animation: slideUp .2s ease both;
}

.client-card-top {
    display: flex; align-items: flex-start;
    gap: 12px; margin-bottom: 12px;
}

.client-avatar {
    width: 44px; height: 44px;
    border-radius: 13px;
    font-size: 1.1rem; font-weight: 800;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.client-info { flex: 1; min-width: 0; }
.client-name {
    font-size: .92rem; font-weight: 700; color: var(--text-primary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.client-meta { font-size: .72rem; color: var(--text-secondary); margin-top: 2px; }

.client-badges { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; flex-shrink: 0; }

.badge {
    font-size: .62rem; font-weight: 800;
    padding: 3px 9px; border-radius: 100px;
    letter-spacing: .3px;
}
.badge-green { background: var(--green-light); color: #16a34a; }
.badge-red { background: var(--danger-light); color: var(--danger); }
.badge-plan { }

.client-stats {
    display: flex; gap: 0;
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 12px;
}
.stat-item { flex: 1; }
.stat-label { font-size: .6rem; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: .5px; }
.stat-val { font-size: .78rem; font-weight: 700; color: var(--text-primary); margin-top: 2px; }
.stat-val.danger { color: var(--danger); }

.client-actions { display: flex; gap: 7px; }

/* ── BUTTONS ──────────────────────────────────────────── */
.btn-outline, .btn-teal, .btn-purple {
    flex: 1; padding: 9px 0;
    border-radius: var(--radius-sm);
    font-weight: 700; font-size: .78rem;
    cursor: pointer; font-family: inherit;
    transition: all .12s;
}
.btn-outline { background: var(--surface); border: 1.5px solid var(--border); color: var(--text-primary); }
.btn-teal { background: var(--teal); border: none; color: white; }
.btn-purple { background: var(--purple); border: none; color: white; }
.btn-outline:active, .btn-teal:active, .btn-purple:active { transform: scale(.97); }
.btn-purple.disabled { opacity: .4; pointer-events: none; }

/* ── REQUEST CARD ─────────────────────────────────────── */
.request-card {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    margin-bottom: 8px;
    box-shadow: var(--shadow-sm);
    display: flex; align-items: center; justify-content: space-between;
    cursor: pointer;
    transition: background .12s;
    animation: slideUp .2s ease both;
}
.request-card:active { background: var(--bg); }
.request-name { font-size: .9rem; font-weight: 700; }
.request-meta { font-size: .72rem; color: var(--text-secondary); margin-top: 2px; }
.plan-tag { font-size: .7rem; font-weight: 700; margin-top: 4px; display: block; }

.status-pill {
    font-size: .62rem; font-weight: 800;
    padding: 4px 11px; border-radius: 100px;
    letter-spacing: .3px; flex-shrink: 0;
}
.status-pending { background: #fef3c7; color: #92400e; }
.status-rejected { background: var(--danger-light); color: var(--danger); }

/* ── BROADCAST ────────────────────────────────────────── */
#sa-broadcast-panel {
    flex: 1; flex-direction: column;
    padding: 16px; gap: 12px;
    display: none;
}

#broadcast-history {
    flex: 1; overflow-y: auto;
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 12px;
    display: flex; flex-direction: column; gap: 8px;
}

.broadcast-msg {
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 10px 13px;
}
.msg-text { font-size: .87rem; color: var(--text-primary); line-height: 1.5; }
.msg-time { font-size: .68rem; color: var(--text-tertiary); margin-top: 4px; display: block; }

.broadcast-input-row {
    display: flex; gap: 10px; flex-shrink: 0;
}
#broadcast-input {
    flex: 1; padding: 12px 16px;
    background: var(--surface); border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    font-family: inherit; font-size: .88rem; color: var(--text-primary);
    outline: none;
}
#broadcast-input:focus { border-color: var(--teal); }

.send-btn {
    padding: 0 18px; background: var(--teal); border: none;
    border-radius: var(--radius-md); color: white; cursor: pointer;
    display: flex; align-items: center; gap: 6px;
    font-size: .85rem; font-weight: 700; font-family: inherit;
}

/* ── SUPPORT CHAT ─────────────────────────────────────── */
#sa-support-panel {
    flex: 1; display: none;
    overflow: hidden;
}

.support-layout {
    display: flex; height: 100%;
}

.support-sidebar {
    width: 100%; flex-shrink: 0;
    display: flex; flex-direction: column;
    border-right: 1px solid var(--border);
    overflow: hidden;
}

/* On wider screens show side by side */
@media (min-width: 600px) {
    .support-sidebar { width: 280px; }
    .support-main { flex: 1; }
}

.support-sidebar-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-size: .88rem; font-weight: 700;
}

.chat-list { flex: 1; overflow-y: auto; }

.chat-list-item {
    display: flex; align-items: center; gap: 11px;
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background .1s;
    position: relative;
}
.chat-list-item:active, .chat-list-item.active { background: var(--teal-light); }
.chat-list-item.unread .chat-item-name { font-weight: 800; }

.chat-avatar {
    width: 42px; height: 42px;
    border-radius: 13px;
    font-size: 1rem; font-weight: 800;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.chat-item-info { flex: 1; min-width: 0; }
.chat-item-top { display: flex; justify-content: space-between; align-items: center; }
.chat-item-name { font-size: .87rem; font-weight: 600; }
.chat-item-time { font-size: .68rem; color: var(--text-tertiary); }
.chat-item-preview {
    font-size: .75rem; color: var(--text-secondary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-top: 2px;
}
.chat-plan-badge { font-size: .62rem; font-weight: 700; }
.unread-dot {
    width: 8px; height: 8px;
    background: var(--teal); border-radius: 50%;
    flex-shrink: 0;
}

.support-main {
    flex: 1; display: flex; flex-direction: column;
    overflow: hidden; background: var(--bg);
}

.support-empty-state {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    color: var(--text-tertiary); gap: 10px; font-size: .88rem;
}

.chat-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    display: flex; align-items: center; gap: 11px;
    flex-shrink: 0;
}
.chat-header-avatar {
    width: 36px; height: 36px; border-radius: 11px;
    font-size: .9rem; font-weight: 800;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.chat-header-info { flex: 1; }
.chat-header-name { font-size: .9rem; font-weight: 700; }
.chat-header-meta { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.chat-info-btn {
    background: none; border: none; cursor: pointer;
    color: var(--text-tertiary); padding: 6px;
    border-radius: 8px;
    transition: background .12s;
}
.chat-info-btn:active { background: var(--bg); }

.sessions-strip {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 8px 12px;
    display: flex; gap: 6px; overflow-x: auto;
    flex-shrink: 0;
}
.session-btn {
    padding: 5px 13px; border-radius: 100px;
    border: 1.5px solid var(--border);
    background: var(--surface); color: var(--text-secondary);
    font-size: .75rem; font-weight: 600; cursor: pointer;
    font-family: inherit; white-space: nowrap;
    transition: all .12s;
}
.session-btn.active { background: var(--teal); border-color: var(--teal); color: white; }
.session-btn.resolved { opacity: .6; }

.chat-messages {
    flex: 1; overflow-y: auto;
    padding: 14px 16px;
    display: flex; flex-direction: column; gap: 10px;
}

.msg-row { display: flex; }
.user-row { justify-content: flex-start; }
.admin-row { justify-content: flex-end; }

.msg-bubble {
    max-width: 78%;
    padding: 10px 14px;
    font-size: .87rem; line-height: 1.6;
    position: relative;
}
.user-bubble {
    background: var(--surface);
    border-radius: 4px 16px 16px 16px;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}
.admin-bubble {
    background: linear-gradient(135deg, var(--teal), #0EA5E9);
    border-radius: 16px 4px 16px 16px;
    color: white;
}
.msg-time-inline {
    display: block; font-size: .62rem;
    margin-top: 4px; opacity: .7;
}
.user-bubble .msg-time-inline { color: var(--text-tertiary); }

.chat-input-bar {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 10px 12px;
    display: flex; align-items: flex-end; gap: 9px;
    flex-shrink: 0;
}
.chat-textarea {
    flex: 1; background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: 22px;
    padding: 10px 16px;
    font-size: .87rem; font-family: inherit; color: var(--text-primary);
    resize: none; max-height: 110px; line-height: 1.5; outline: none;
    transition: border-color .15s;
}
.chat-textarea:focus { border-color: var(--teal); }
.chat-send-btn {
    width: 40px; height: 40px; border-radius: 50%;
    background: linear-gradient(135deg, var(--teal), #0EA5E9);
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 2px 10px rgba(13,148,136,.35);
    transition: transform .12s;
}
.chat-send-btn:active { transform: scale(.9); }

/* ── MODAL ────────────────────────────────────────────── */
.modal-overlay-bg {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(0,0,0,.4);
    backdrop-filter: blur(4px);
    display: none;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
}

.modal-sheet {
    background: var(--surface);
    border-radius: 24px 24px 0 0;
    width: 100%; max-width: 560px;
    max-height: 88dvh;
    overflow-y: auto;
    padding: 6px 20px 40px;
    transform: translateY(30px);
    opacity: 0;
    transition: all .3s cubic-bezier(.32,.72,0,1);
}
.modal-sheet::before {
    content: '';
    display: block; width: 36px; height: 4px;
    background: #e5e7eb;
    border-radius: 2px;
    margin: 10px auto 20px;
}
.modal-sheet.show { transform: translateY(0); opacity: 1; }

.modal-inner { display: flex; flex-direction: column; gap: 12px; }

.modal-icon-row { display: flex; align-items: center; gap: 13px; margin-bottom: 4px; }
.modal-icon {
    width: 48px; height: 48px; border-radius: 14px;
    font-size: 1.4rem;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.modal-icon.teal { background: var(--teal-light); }
.modal-icon.purple { background: var(--purple-light); }
.modal-title { font-size: 1.05rem; font-weight: 800; color: var(--text-primary); }
.modal-sub { font-size: .78rem; color: var(--text-secondary); margin-top: 2px; }

.field-label {
    font-size: .72rem; font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase; letter-spacing: .5px;
}

.modal-input {
    width: 100%; padding: 12px 14px;
    background: var(--bg); border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    font-family: inherit; font-size: .88rem; color: var(--text-primary);
    outline: none; margin-bottom: 4px;
    transition: border-color .15s;
}
.modal-input:focus { border-color: var(--teal); }

.plan-list { display: flex; flex-direction: column; gap: 7px; }
.plan-option {
    padding: 12px 14px; border-radius: var(--radius-md);
    border: 2px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    cursor: pointer; transition: all .12s;
}
.plan-option.selected { border-color: var(--teal); background: var(--teal-light); }
.plan-option-name { font-weight: 700; font-size: .9rem; }
.plan-option-price { font-weight: 800; font-size: .88rem; }
.current-tag {
    font-size: .62rem; background: var(--bg);
    color: var(--text-secondary); padding: 2px 7px;
    border-radius: 100px; margin-left: 7px;
}

.info-banner {
    padding: 10px 14px; border-radius: var(--radius-sm);
    font-size: .78rem; font-weight: 600; line-height: 1.5;
}
.teal-banner { background: var(--teal-light); border: 1px solid #99f6e4; color: #0f766e; }
.purple-banner { background: var(--purple-light); border: 1px solid #c7d2fe; color: #4338ca; }

.modal-btn {
    width: 100%; padding: 14px;
    border-radius: var(--radius-md); border: none;
    font-weight: 800; font-size: .9rem; cursor: pointer;
    font-family: inherit; margin-top: 4px;
    transition: all .12s;
}
.modal-btn:active { transform: scale(.98); }
.teal-btn { background: linear-gradient(135deg, var(--teal), #0EA5E9); color: white; }
.purple-btn { background: linear-gradient(135deg, var(--purple), #818cf8); color: white; }
.danger-btn { background: var(--danger); color: white; }
.outline-btn { background: var(--surface); border: 1.5px solid var(--border); color: var(--text-primary); }

.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions .modal-btn { margin-top: 0; }

.success-modal, .danger-modal {
    text-align: center; padding: 24px 16px;
    display: flex; flex-direction: column; gap: 10px;
    align-items: center;
}
.success-title, .danger-title {
    font-size: 1.15rem; font-weight: 800; color: var(--text-primary);
}
.success-body, .danger-body {
    font-size: .83rem; color: var(--text-secondary); line-height: 1.7;
}

/* ── STAFF ROWS ───────────────────────────────────────── */
.staff-row {
    display: flex; align-items: center; gap: 8px;
    background: var(--bg); padding: 9px 12px;
    border-radius: var(--radius-sm); margin-bottom: 5px;
    font-size: .83rem;
}
.staff-dot {
    width: 8px; height: 8px;
    border-radius: 50%; background: var(--text-tertiary);
    flex-shrink: 0;
}
.staff-row span:nth-child(2) { flex: 1; }
.remove-btn {
    background: none; border: none; color: var(--danger);
    cursor: pointer; font-size: .8rem; padding: 2px 6px;
}
.staff-add-row { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.staff-add-row .btn-outline { padding: 10px 14px; flex: none; }

/* ── COMPANY INFO SHEET ───────────────────────────────── */
.info-sheet { padding: 8px 4px 20px; }
.info-avatar {
    width: 56px; height: 56px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--teal), #0EA5E9);
    color: white; font-size: 1.4rem; font-weight: 800;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 10px;
}
.info-name { text-align: center; font-size: 1.05rem; font-weight: 700; margin-bottom: 16px; }
.info-rows { display: flex; flex-direction: column; gap: 0; }
.info-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 0; border-bottom: 1px solid var(--border);
    font-size: .85rem;
}
.info-row span:first-child { color: var(--text-secondary); }
.info-row span:last-child { font-weight: 600; text-align: right; max-width: 60%; }

/* ── STATES ───────────────────────────────────────────── */
.loading-state {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 50px; gap: 12px;
}
.spinner {
    width: 28px; height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--teal);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
.empty-state {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 50px 20px; gap: 8px;
    color: var(--text-tertiary);
}
.empty-icon { font-size: 2.5rem; }
.empty-state p { font-size: .88rem; }

/* ── ANIMATIONS ───────────────────────────────────────── */
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp { from { opacity: 0; transform: translateY(12px) } to { opacity: 1; transform: translateY(0) } }
@keyframes spin { to { transform: rotate(360deg) } }

/* ── SCROLLBARS ───────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,.12); border-radius: 2px; }

.hidden { display: none !important; }
