/* MaDaMe MDM - Admin UI Styles */

:root {
    --bg: #0f0f11;
    --bg-card: #1a1a1f;
    --bg-hover: #252529;
    --bg-input: #252529;
    --border: #2e2e35;
    --text: #e4e4e7;
    --text-muted: #71717a;
    --text-dim: #52525b;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --success: #22c55e;
    --warning: #eab308;
    --danger: #ef4444;
    --info: #3b82f6;
    --radius: 12px;
    --radius-sm: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-text-size-adjust: 100%;
}

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

/* ── Layout ── */
.layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-logo {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
    padding: 8px 12px;
    margin-bottom: 16px;
    letter-spacing: -0.02em;
}
.sidebar-logo span { color: var(--accent); }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.15s;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.nav-section {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    padding: 16px 12px 6px;
}

/* ── Mobile header ── */
.mobile-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 4px 10px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 40;
    height: 36px;
}
.mobile-header .sidebar-logo { font-size: 0.95rem; }
.mobile-header .btn { min-height: 24px; padding: 2px 8px; font-size: 0.75rem; }

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 49;
}

/* ── Main content ── */
.main {
    padding: 32px;
    max-width: 1400px;
    min-width: 0;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-title { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }

/* ── Cards ── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}
.stat-value { font-size: 2rem; font-weight: 700; letter-spacing: -0.03em; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

/* ── Tables ── */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }

thead th {
    background: var(--bg-card);
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
tbody tr:hover { background: var(--bg-hover); }
tbody tr:last-child td { border-bottom: none; }

/* ── Badges ──
   Contrast was previously ~2.5:1 (same-hue text-on-tint) which failed
   WCAG AA. Brightened the foreground colors to near-white hues of each
   status so the text is legible against the 15%-alpha background.
*/
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-success { background: rgba(34,197,94,0.18); color: #86efac; }
.badge-warning { background: rgba(234,179,8,0.18); color: #fde047; }
.badge-danger  { background: rgba(239,68,68,0.18); color: #fca5a5; }
.badge-info    { background: rgba(99,102,241,0.22); color: #c7d2fe; }
.badge-neutral { background: rgba(113,113,122,0.25); color: #d4d4d8; }
.badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    min-height: 44px; /* touch target */
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; border: none; }
.btn-danger:hover { opacity: 0.9; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-secondary { background: var(--bg-hover); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; min-height: 36px; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.form-input, .form-select, select.form-input, textarea.form-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 16px; /* prevents iOS zoom on focus */
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    min-height: 44px;
}
.form-input:focus, .form-select:focus, select.form-input:focus, textarea.form-input:focus {
    border-color: var(--accent);
}

/* ── Accessible focus rings ──
   Only visible for keyboard-driven focus (pointer interactions don't
   get the ring, so mouse users still see clean hover states). Applied
   to every interactive surface: buttons, inputs, selects, anchors,
   tabs, sidebar nav items, split toggles, modal close controls.
*/
.btn:focus-visible,
.form-input:focus-visible,
.form-select:focus-visible,
select.form-input:focus-visible,
textarea.form-input:focus-visible,
a:focus-visible,
.nav-item:focus-visible,
.tab:focus-visible,
.split-toggle .split-btn:focus-visible,
[role="button"]:focus-visible,
.icon-btn:focus-visible,
details summary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}
.form-input:focus-visible,
.form-select:focus-visible,
textarea.form-input:focus-visible {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}

/* ── Modals ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
    padding: 16px;
}
.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 480px;
    width: 100%;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.modal-sm { max-width: 400px; }
.modal-lg { max-width: 640px; }
.modal-xl { max-width: 860px; }
.modal-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 16px; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}
.modal-footer .btn { flex: 1; min-width: 120px; }
@media (min-width: 480px) {
    .modal-footer .btn { flex: 0 1 auto; }
}

/* ── Toasts ── */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: calc(100vw - 40px);
}
.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    font-size: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 4px;
    animation: slideIn 0.3s ease;
    max-width: 360px;
}
.toast-fade { opacity: 0; transition: opacity 0.3s; }
@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ── QR ── */
.qr-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 24px;
}
.qr-container img, .qr-container canvas {
    border-radius: var(--radius);
    background: #fff;
    padding: 16px;
}

/* ── Logout button (sidebar footer) ── */
.btn-logout {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.75rem;
    padding: 4px 8px;
    border-radius: 4px;
    transition: color 0.15s;
}
.btn-logout:hover { color: var(--danger); }

/* ── WS indicator ── */
.ws-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
    transition: background 0.3s;
    flex-shrink: 0;
}
.ws-indicator.connected { background: var(--success); }

/* ── Device detail ── */
.info-table { width: 100%; border-collapse: collapse; }
.info-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); font-size: 0.9rem; word-break: break-all; }
.info-table td:first-child { width: 100px; white-space: nowrap; word-break: normal; }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ── Tabs ── */
.tab-bar { display:flex; gap:2px; border-bottom:1px solid var(--border); }
.tab { padding:8px 20px; font-size:0.85rem; font-weight:500; color:var(--text-dim); background:none; border:none; border-bottom:2px solid transparent; cursor:pointer; margin-bottom:-1px; transition:color .15s,border-color .15s; }
.tab:hover { color:var(--text); }
.tab.active { color:var(--accent); border-bottom-color:var(--accent); }

/* ── Split toggle buttons ── */
.split-toggle {
    display: flex;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
}
.split-toggle .split-label {
    flex: 1;
    padding: 8px 12px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    background: transparent;
}
.split-toggle .split-btn {
    padding: 8px 14px;
    font-size: 0.8rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
    background: transparent;
    color: var(--text-muted);
    border-left: 1px solid var(--border);
    min-height: 40px;
}
.split-toggle .split-btn:hover { background: var(--bg-hover); color: var(--text); }
.split-toggle .split-btn.on { color: var(--success); }
.split-toggle .split-btn.on:hover { background: rgba(34,197,94,0.1); }
.split-toggle .split-btn.off { color: var(--danger); }
.split-toggle .split-btn.off:hover { background: rgba(239,68,68,0.1); }

/* ── Alerts ──
   Unified error / info / warning panels. Replaces the hand-rolled
   inline pattern `display:none;color:var(--danger);background:...`
   that was duplicated across 5+ templates. Keep `hidden` alongside
   `alert` if the element starts collapsed — `.hidden` forces
   display:none and wins over the flex display below.
*/
.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-top: 12px;
    font-size: 0.9rem;
    line-height: 1.4;
    border: 1px solid transparent;
}
.alert-danger  { color: #fca5a5; background: rgba(239,68,68,0.12); border-color: rgba(239,68,68,0.3); }
.alert-warning { color: #fde047; background: rgba(234,179,8,0.12); border-color: rgba(234,179,8,0.3); }
.alert-info    { color: #c7d2fe; background: rgba(99,102,241,0.15); border-color: rgba(99,102,241,0.3); }
.alert-success { color: #86efac; background: rgba(34,197,94,0.12); border-color: rgba(34,197,94,0.3); }

/* ── Skeleton loader ── */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-hover) 0%,
        var(--bg-input) 50%,
        var(--bg-hover) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-pulse 1.4s ease-in-out infinite;
    border-radius: var(--radius-sm);
    color: transparent !important;
    user-select: none;
    pointer-events: none;
}
.skeleton-line  { height: 0.9em; margin: 4px 0; width: 100%; }
.skeleton-short { width: 40%; }
.skeleton-btn   { height: 44px; width: 100%; }
@keyframes skeleton-pulse {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── Icon button ──
   Square, no text, used for close/dismiss/copy-to-clipboard/remove-tag
   actions. 36px touch target on mobile via the base .btn inheritance.
*/
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

/* ── Text helpers ── */
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-success { color: var(--success); }
.text-info    { color: var(--info); }
.text-accent  { color: var(--accent); }
.text-bold    { font-weight: 600; }
.text-xs      { font-size: 0.75rem; }
.text-lg      { font-size: 1.05rem; }
.text-xl      { font-size: 1.25rem; }
.text-right   { text-align: right; }
.text-left    { text-align: left; }
.text-nowrap  { white-space: nowrap; }
.text-break   { word-break: break-all; }

/* ── Click-target label row ──
   The 60-occurrence `display:flex;align-items:center;gap:6px;cursor:pointer`
   pattern — checkbox/radio labels across every modal. Unified here.
*/
.check-row {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}
.check-row-block { margin-bottom: 12px; }

/* ── Section title inside a card ── */
.section-title {
    font-weight: 600;
    margin-bottom: 12px;
    font-size: 0.95rem;
}
.section-subtitle {
    font-weight: 600;
    margin: 8px 0 6px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ── Two-column form/detail grid ── */
.grid-form-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
}

/* ── Horizontal rule inside cards ── */
hr.rule,
.card hr {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 16px 0;
}

/* ── Utilities ── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.justify-center { justify-content: center; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-5 { gap: 20px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-5 { margin-top: 20px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-5 { margin-bottom: 20px; }
.mb-0 { margin-bottom: 0; }
.w-full { width: 100%; }
.max-w-sm { max-width: 420px; }
.max-w-md { max-width: 500px; }
.max-w-lg { max-width: 600px; }
.text-center { text-align: center; }
.text-sm { font-size: 0.85rem; }
.text-muted { color: var(--text-muted); }
.text-dim { color: var(--text-dim); }
.cursor-pointer { cursor: pointer; }
.hidden { display: none !important; }

/* ── Empty states ── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state h3 { font-size: 1.1rem; margin-bottom: 8px; color: var(--text); }
.empty-state p { margin-bottom: 20px; max-width: 44ch; margin-left: auto; margin-right: auto; }
.empty-state .btn { margin-top: 4px; }
.empty-state-icon {
    display: inline-flex;
    width: 56px;
    height: 56px;
    align-items: center;
    justify-content: center;
    background: var(--bg-hover);
    border-radius: 999px;
    margin-bottom: 16px;
    color: var(--text-muted);
}
.empty-state-icon svg { width: 24px; height: 24px; }

/* ── Login / Invite page ── */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}
.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px;
    max-width: 400px;
    width: 100%;
    text-align: center;
}
.login-card h1 { font-size: 1.8rem; margin-bottom: 8px; }
.login-card p { color: var(--text-muted); margin-bottom: 24px; }

/* ── Detail grid ── */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 16px;
}
.detail-item { padding: 12px 0; border-bottom: 1px solid var(--border); }
.detail-label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 4px; }
.detail-value { font-weight: 500; }

/* ══════════════════════════════════════════════════
   RESPONSIVE — TABLET (<=1024px)
   ══════════════════════════════════════════════════ */
@media (max-width: 1024px) {
    .layout { grid-template-columns: 200px 1fr; }
    .sidebar { padding: 16px 12px; }
    .main { padding: 24px; }
}

/* ══════════════════════════════════════════════════
   RESPONSIVE — MOBILE (<=768px)
   ══════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .layout { grid-template-columns: 1fr; }

    /* Sidebar becomes slide-over drawer */
    .sidebar {
        display: none;
        position: fixed;
        z-index: 50;
        width: 260px;
        height: 100vh;
        top: 0;
        left: 0;
        box-shadow: 4px 0 24px rgba(0,0,0,0.4);
    }
    .sidebar.open { display: flex; }
    .sidebar.open ~ .sidebar-backdrop { display: block; }

    .mobile-header { display: flex !important; }

    .main { padding: 8px 10px; }

    .page-header { margin-bottom: 8px; gap: 4px; }
    .page-title { font-size: 1.1rem; }

    .grid-2, .action-grid {
        grid-template-columns: 1fr;
    }

    .card { padding: 12px; }
    .mb-4 { margin-bottom: 10px; }
    .gap-4 { gap: 10px; }

    /* Tables: tighter padding */
    thead th { padding: 10px 12px; font-size: 0.75rem; }
    tbody td { padding: 10px 12px; }

    /* Stat cards: 2 columns on phone */
    .card-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-card { padding: 14px; }
    .stat-value { font-size: 1.5rem; }

    /* Modals: full width, bottom-sheet style on small screens */
    .modal-overlay {
        align-items: flex-end;
        padding: 0;
    }
    .modal {
        max-width: 100%;
        border-radius: var(--radius) var(--radius) 0 0;
        max-height: 85vh;
        padding: 20px;
    }

    /* Login card */
    .login-card { padding: 24px; }

    /* Toast: full width at bottom */
    #toast-container {
        left: 16px;
        right: 16px;
        bottom: 16px;
    }
    .toast { max-width: 100%; }

    /* Empty state less padding */
    .empty-state { padding: 32px 16px; }
}

/* ══════════════════════════════════════════════════
   RESPONSIVE — SMALL PHONE (<=420px)
   ══════════════════════════════════════════════════ */
@media (max-width: 420px) {
    html { font-size: 14px; }
    .main { padding: 12px; }
    .card { padding: 12px; }
    .page-header { margin-bottom: 16px; }
    .btn { padding: 10px 14px; font-size: 0.85rem; }
    .card-grid { grid-template-columns: 1fr; }
}
