/* ═══════════════════════════════════════════════════════════════════════════
   PatrolOne Admin Dashboard — Design System
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
    --color-primary:    #007AFF;
    --color-primary-dk: #005EC4;
    --color-success:    #34C759;
    --color-danger:     #FF3B30;
    --color-warning:    #FF9500;
    --color-info:       #5AC8FA;

    --sidebar-bg:       #1a1a2e;
    --sidebar-hover:    #16213e;
    --sidebar-active:   #0f3460;
    --sidebar-text:     #a2a8b4;
    --sidebar-text-act: #ffffff;
    --sidebar-width:    240px;

    --bg-body:          #f2f4f7;
    --bg-card:          #ffffff;
    --bg-input:         #f7f8fa;

    --text-primary:     #1a1a2e;
    --text-secondary:   #6b7280;
    --text-muted:       #9ca3af;

    --border-color:     #e5e7eb;
    --radius:           8px;
    --radius-lg:        12px;
    --shadow-sm:        0 1px 2px rgba(0,0,0,.05);
    --shadow:           0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-lg:        0 4px 12px rgba(0,0,0,.1);
    --transition:       .2s ease;
}

/* ── Reset ─────────────────────────────────────────────────────────────── */

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-body);
    -webkit-font-smoothing: antialiased;
}

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

/* ── Layout ────────────────────────────────────────────────────────────── */

.dashboard-layout {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 24px 32px 48px;
    min-width: 0;
}

.content-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
}

.content-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
}

.content-actions { display: flex; gap: 8px; }

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

.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow-y: auto;
    transition: transform var(--transition);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 20px 8px;
}

.brand-icon { font-size: 24px; }
.brand-text { font-size: 18px; font-weight: 700; color: #fff; }

.sidebar-org {
    padding: 8px 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    display: flex;
    flex-direction: column;
}

.org-name { font-size: 13px; font-weight: 600; color: #fff; }
.org-role  { font-size: 11px; color: var(--sidebar-text); text-transform: uppercase; letter-spacing: .5px; }

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--sidebar-text);
    font-size: 13px;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: all var(--transition);
    text-decoration: none;
}

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

.nav-item.active {
    background: var(--sidebar-active);
    color: var(--sidebar-text-act);
    border-left-color: var(--color-primary);
}

.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
    padding: 12px 0;
    border-top: 1px solid rgba(255,255,255,.08);
}

.sidebar-user {
    padding: 4px 20px 8px;
}

.user-name { font-size: 12px; color: var(--sidebar-text); }

.nav-logout { color: #ef4444 !important; }
.nav-logout:hover { background: rgba(239,68,68,.1) !important; }

.sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px; left: 12px;
    z-index: 200;
    background: var(--sidebar-bg);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 18px;
    cursor: pointer;
}

/* ── Cards ─────────────────────────────────────────────────────────────── */

.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    padding: 20px;
}

.card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: .3px;
    margin-bottom: 12px;
}

/* Metric cards */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.metric-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    padding: 20px;
}

.metric-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: .3px;
}

.metric-value {
    font-size: 28px;
    font-weight: 700;
    margin-top: 4px;
    line-height: 1.2;
}

.metric-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ── Grid layouts ──────────────────────────────────────────────────────── */

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 24px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; margin-bottom: 24px; }

/* ── Tables ────────────────────────────────────────────────────────────── */

.table-wrapper {
    overflow-x: auto;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table thead {
    background: var(--bg-input);
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .3px;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}

.data-table th:hover { color: var(--text-primary); }
.data-table th.sort-asc::after  { content: ' \25B2'; font-size: 10px; }
.data-table th.sort-desc::after { content: ' \25BC'; font-size: 10px; }

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.data-table tbody tr:hover { background: #f9fafb; }
.data-table tbody tr:last-child td { border-bottom: none; }

/* ── Badges ────────────────────────────────────────────────────────────── */

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .2px;
}

.badge-success { background: #dcfce7; color: #166534; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-ios     { background: #e0e7ff; color: #3730a3; }
.badge-android { background: #d1fae5; color: #065f46; }
.badge-owner   { background: #fce7f3; color: #9d174d; }
.badge-admin   { background: #dbeafe; color: #1e40af; }
.badge-member  { background: #f3f4f6; color: #374151; }

/* ── Buttons ───────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover { text-decoration: none; }

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

.btn-success { background: var(--color-success); color: #fff; }
.btn-success:hover { opacity: .9; }

.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { opacity: .9; }

.btn-outline {
    background: transparent;
    border-color: var(--border-color);
    color: var(--text-primary);
}
.btn-outline:hover { background: var(--bg-input); }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

.btn-sync {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
    transition: all .3s ease;
}
.btn-sync:hover { background: var(--color-primary-dk); border-color: var(--color-primary-dk); }
.btn-sync.synced { background: var(--color-success); border-color: var(--color-success); }
.btn-sync.synced:hover { opacity: .9; }
.btn-sync:disabled { opacity: .6; cursor: not-allowed; }

.sync-time { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ── Forms ──────────────────────────────────────────────────────────────── */

.form-group { margin-bottom: 16px; }

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    background: var(--bg-input);
    color: var(--text-primary);
    transition: border-color var(--transition);
}

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

.form-textarea { resize: vertical; min-height: 80px; }

.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }

.form-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}

.toggle-switch {
    position: relative;
    width: 40px;
    height: 22px;
    background: #d1d5db;
    border-radius: 11px;
    transition: background var(--transition);
    flex-shrink: 0;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px; left: 2px;
    width: 18px; height: 18px;
    background: #fff;
    border-radius: 50%;
    transition: transform var(--transition);
}

.form-toggle input { display: none; }
.form-toggle input:checked + .toggle-switch { background: var(--color-primary); }
.form-toggle input:checked + .toggle-switch::after { transform: translateX(18px); }

.toggle-label { font-size: 14px; font-weight: 500; }

/* ── Filters bar ───────────────────────────────────────────────────────── */

.filters-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.filters-bar .form-input,
.filters-bar .form-select {
    width: auto;
    min-width: 140px;
}

.search-input {
    flex: 1;
    min-width: 200px;
    max-width: 320px;
}

/* ── Compliance grid ───────────────────────────────────────────────────── */

.compliance-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.compliance-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: box-shadow var(--transition);
}

.compliance-card:hover { box-shadow: var(--shadow); }

.compliance-dot {
    width: 12px; height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dot-green  { background: var(--color-success); }
.dot-red    { background: var(--color-danger); }
.dot-yellow { background: var(--color-warning); }

.compliance-info { flex: 1; min-width: 0; }
.compliance-device { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.compliance-owner  { font-size: 12px; color: var(--text-muted); }

/* ── Activity feed ─────────────────────────────────────────────────────── */

.activity-feed { list-style: none; }

.activity-item {
    display: flex;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
}

.activity-item:last-child { border-bottom: none; }
.activity-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.activity-text { flex: 1; color: var(--text-primary); }
.activity-time { color: var(--text-muted); font-size: 12px; white-space: nowrap; }

/* ── Scores ────────────────────────────────────────────────────────────── */

.score-good { color: var(--color-success); }
.score-warn { color: var(--color-warning); }
.score-bad  { color: var(--color-danger); }

.score-large {
    font-size: 48px;
    font-weight: 700;
    line-height: 1;
}

/* ── Charts ────────────────────────────────────────────────────────────── */

.chart-container {
    position: relative;
    height: 280px;
}

.chart-container-sm {
    position: relative;
    height: 200px;
}

/* ── Modal ──────────────────────────────────────────────────────────────── */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.visible {
    display: flex;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 540px;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 { font-size: 16px; font-weight: 700; }

.modal-close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0 4px;
}

.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; gap: 8px; }

/* ── Toast ──────────────────────────────────────────────────────────────── */

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    z-index: 2000;
    animation: slideIn .3s ease, fadeOut .3s ease 3s forwards;
}

.toast-success { background: var(--color-success); }
.toast-error   { background: var(--color-danger); }
.toast-info    { background: var(--color-info); }
.toast-warning { background: var(--color-warning); }

@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fadeOut  { to { opacity: 0; pointer-events: none; } }

/* ── Login page ────────────────────────────────────────────────────────── */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--sidebar-bg);
}

.login-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 400px;
    max-width: 92%;
    padding: 40px 32px;
}

.login-brand {
    text-align: center;
    margin-bottom: 28px;
}

.login-brand .brand-icon { font-size: 36px; }
.login-brand h2 { font-size: 20px; font-weight: 700; margin-top: 8px; }
.login-brand p  { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.login-error {
    background: #fee2e2;
    color: #991b1b;
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
}

/* ── Detail header ─────────────────────────────────────────────────────── */

.detail-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.detail-back {
    font-size: 20px;
    color: var(--text-muted);
    text-decoration: none;
}

.detail-meta { flex: 1; }
.detail-meta h2 { font-size: 18px; font-weight: 700; }
.detail-meta p  { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }

/* ── Stats row ─────────────────────────────────────────────────────────── */

.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.stat-item {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 14px;
    text-align: center;
}

.stat-value { font-size: 22px; font-weight: 700; }
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .3px; margin-top: 2px; }

/* ── Violation list ────────────────────────────────────────────────────── */

.violation-list { list-style: none; }

.violation-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
}

.violation-item:last-child { border-bottom: none; }
.violation-type { font-weight: 600; color: var(--color-danger); min-width: 160px; }
.violation-desc { color: var(--text-secondary); }

/* ── Empty state ───────────────────────────────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}

.empty-state-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state-text { font-size: 15px; }

/* ── Danger zone ───────────────────────────────────────────────────────── */

.danger-zone {
    border: 1px solid var(--color-danger);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-top: 24px;
}

.danger-zone h3 { color: var(--color-danger); font-size: 15px; margin-bottom: 8px; }
.danger-zone p  { font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; }

/* ── Invite code display ───────────────────────────────────────────────── */

.invite-code {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 2px;
    text-align: center;
    padding: 16px;
    background: var(--bg-input);
    border-radius: var(--radius);
    border: 1px dashed var(--border-color);
    margin: 12px 0;
}

/* ── Onboarding Steps ─────────────────────────────────────────────────── */
.onboarding-guide { max-width: 720px; }
.onboarding-step { display: flex; gap: 16px; padding: 20px; margin-bottom: 12px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; transition: border-color 0.2s; }
.onboarding-step:hover { border-color: var(--accent); }
.onboarding-step.step-done { border-color: var(--green); opacity: 0.85; }
.step-number { width: 36px; height: 36px; border-radius: 10px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.9rem; flex-shrink: 0; }
.step-done .step-number { background: var(--green); font-size: 16px; }
.step-content h3 { font-size: 0.95rem; font-weight: 700; margin-bottom: 4px; }
.step-content p { font-size: 0.82rem; color: var(--text-secondary); margin-bottom: 10px; line-height: 1.5; }

/* ── Responsive ────────────────────────────────────────────────────────── */

@media (max-width: 1024px) {
    .grid-2 { grid-template-columns: 1fr; }
    .grid-3 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: none; }
    .sidebar-toggle { display: block; }

    .main-content {
        margin-left: 0;
        padding: 16px;
        padding-top: 56px;
    }

    .content-header { flex-direction: column; align-items: flex-start; }

    .metrics-grid { grid-template-columns: 1fr 1fr; }
    .grid-3 { grid-template-columns: 1fr; }

    .filters-bar { flex-direction: column; align-items: stretch; }
    .search-input { max-width: none; }

    .compliance-grid { grid-template-columns: 1fr 1fr; }

    .form-row { flex-direction: column; gap: 0; }

    .detail-header { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 480px) {
    .metrics-grid { grid-template-columns: 1fr; }
    .compliance-grid { grid-template-columns: 1fr; }
}
