/* ================================================================
   SafeControl – Dark Admin Panel
   ================================================================ */

:root {
    --bg:           #0f172a;
    --bg-surface:   #1e293b;
    --bg-card:      #1e293b;
    --bg-input:     #0f172a;
    --border:       #334155;
    --primary:      #3b82f6;
    --primary-dark: #2563eb;
    --primary-text: #bfdbfe;
    --success:      #22c55e;
    --warning:      #f59e0b;
    --danger:       #ef4444;
    --info:         #06b6d4;
    --text:         #f1f5f9;
    --text-muted:   #94a3b8;
    --text-dim:     #64748b;
    --sidebar-w:    240px;
    --radius:       8px;
    --shadow:       0 4px 6px -1px rgba(0,0,0,.4);
}

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

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

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

/* ================================================================
   App Shell
   ================================================================ */
.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ================================================================
   Sidebar
   ================================================================ */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 16px;
    border-bottom: 1px solid var(--border);
}

.brand-icon { font-size: 1.5rem; }

.brand-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: .3px;
}

.sidebar-links {
    flex: 1;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: .92rem;
    font-weight: 500;
    transition: background .15s, color .15s;
    cursor: pointer;
}

.nav-link:hover {
    background: rgba(59,130,246,.12);
    color: var(--text);
}

.nav-link.active {
    background: rgba(59,130,246,.18);
    color: var(--primary);
}

.nl-icon { font-size: 1rem; width: 20px; text-align: center; }

.sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-user {
    font-size: .85rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-logout {
    font-size: .85rem;
    color: var(--danger);
    padding: 6px 8px;
}

.nav-logout:hover {
    background: rgba(239,68,68,.12);
    color: var(--danger);
}

/* ================================================================
   Main Area
   ================================================================ */
.main-area {
    flex: 1;
    overflow-y: auto;
    background: var(--bg);
}

.main-area--auth {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

/* ================================================================
   Page Container
   ================================================================ */
.page-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 24px;
}

.page-header {
    margin-bottom: 28px;
}

.page-title {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text);
}

.page-subtitle {
    font-size: .9rem;
    color: var(--text-muted);
    margin-top: 4px;
}

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

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 16px;
}

/* ================================================================
   Stat Grid
   ================================================================ */
.stat-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;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-label {
    font-size: .8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    font-weight: 600;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
}

.stat-blue  .stat-value { color: var(--primary); }
.stat-green .stat-value { color: var(--success); }
.stat-amber .stat-value { color: var(--warning); }
.stat-red   .stat-value { color: var(--danger); }
.stat-cyan  .stat-value { color: var(--info); }

.stat-sub {
    font-size: .8rem;
    color: var(--text-muted);
}

/* ================================================================
   Tabs
   ================================================================ */
.tab-bar {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
}

.tab-btn {
    padding: 10px 20px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-size: .92rem;
    font-weight: 500;
    cursor: pointer;
    transition: color .15s, border-color .15s;
    margin-bottom: -1px;
}

.tab-btn:hover { color: var(--text); }

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* ================================================================
   Section: Subscription Breakdown
   ================================================================ */
.sub-breakdown {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 8px;
}

.sub-badge {
    background: rgba(59,130,246,.12);
    color: var(--primary-text);
    border-radius: 20px;
    padding: 4px 12px;
    font-size: .8rem;
    font-weight: 500;
}

/* ================================================================
   Table
   ================================================================ */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

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

thead {
    background: rgba(255,255,255,.04);
}

th {
    padding: 12px 14px;
    text-align: left;
    font-size: .78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 12px 14px;
    border-bottom: 1px solid rgba(51,65,85,.6);
    color: var(--text);
    vertical-align: top;
}

tbody tr:last-child td { border-bottom: none; }

tbody tr:hover td { background: rgba(255,255,255,.03); }

/* ================================================================
   Badges / Status Pills
   ================================================================ */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .3px;
}

.badge-open     { background: rgba(59,130,246,.18); color: var(--primary); }
.badge-progress { background: rgba(245,158,11,.18); color: var(--warning); }
.badge-resolved { background: rgba(34,197,94,.18);  color: var(--success); }
.badge-closed   { background: rgba(100,116,139,.18); color: var(--text-muted); }

.badge-low      { background: rgba(34,197,94,.18);  color: var(--success); }
.badge-medium   { background: rgba(245,158,11,.18); color: var(--warning); }
.badge-high     { background: rgba(239,68,68,.18);  color: var(--danger); }
.badge-critical { background: rgba(239,68,68,.35);  color: #fca5a5; }

/* ================================================================
   Forms
   ================================================================ */
.form-group {
    margin-bottom: 18px;
}

.form-label {
    display: block;
    font-size: .85rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: .4px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: .93rem;
    font-family: inherit;
    transition: border-color .15s, box-shadow .15s;
    outline: none;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,.18);
}

.form-control::placeholder { color: var(--text-dim); }

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2394a3b8' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
    cursor: pointer;
}

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

/* ================================================================
   Buttons
   ================================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: var(--radius);
    font-size: .9rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    cursor: pointer;
    transition: opacity .15s, background .15s;
    white-space: nowrap;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }

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

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

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

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
}
.btn-ghost:hover:not(:disabled) { background: rgba(255,255,255,.06); color: var(--text); }

.btn-sm { padding: 5px 12px; font-size: .82rem; }

/* ================================================================
   Login Page
   ================================================================ */
.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 36px 32px;
    box-shadow: var(--shadow);
}

.login-logo {
    text-align: center;
    margin-bottom: 24px;
}

.login-logo .brand-icon { font-size: 2.5rem; display: block; margin-bottom: 8px; }

.login-logo .brand-name {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
}

.login-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    text-align: center;
    margin-bottom: 24px;
}

.login-error {
    background: rgba(239,68,68,.15);
    border: 1px solid rgba(239,68,68,.35);
    color: #fca5a5;
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: .88rem;
    margin-bottom: 18px;
}

/* ================================================================
   Ticket Detail / Drawer
   ================================================================ */
.ticket-row { cursor: pointer; }

.detail-pane {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-top: 20px;
}

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

.detail-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
}

.detail-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: .83rem;
    color: var(--text-muted);
    margin-bottom: 14px;
}

.detail-body {
    font-size: .93rem;
    color: var(--text);
    line-height: 1.65;
    white-space: pre-wrap;
    margin-bottom: 18px;
}

/* ================================================================
   Loading / Empty States
   ================================================================ */
.loading-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: .9rem;
    gap: 10px;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: .9rem;
}

.empty-icon { font-size: 2.5rem; margin-bottom: 10px; display: block; }

/* ================================================================
   Spinner
   ================================================================ */
.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,.2);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin .7s linear infinite;
    display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ================================================================
   Alert
   ================================================================ */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: .88rem;
    margin-bottom: 16px;
}

.alert-success {
    background: rgba(34,197,94,.12);
    border: 1px solid rgba(34,197,94,.3);
    color: #86efac;
}

.alert-danger {
    background: rgba(239,68,68,.12);
    border: 1px solid rgba(239,68,68,.3);
    color: #fca5a5;
}

/* ================================================================
   Responsive
   ================================================================ */
@media (max-width: 768px) {
    :root { --sidebar-w: 200px; }

    .page-container { padding: 20px 16px; }

    .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
    .app-shell { flex-direction: column; }

    .sidebar {
        width: 100%;
        min-width: unset;
        flex-direction: row;
        border-right: none;
        border-bottom: 1px solid var(--border);
        overflow-x: auto;
        overflow-y: hidden;
        height: auto;
    }

    .sidebar-links { flex-direction: row; padding: 6px; }
    .sidebar-brand { display: none; }
    .sidebar-footer { display: none; }

    .main-area { overflow-y: auto; }
}

/* ================================================================
   Users Page  (.uc-*)
   ================================================================ */

.uc-page   { padding: 2rem; }
.uc-header { margin-bottom: 1.5rem; }
.uc-title  { font-size: 1.5rem; font-weight: 700; margin: 0 0 .25rem; }
.uc-subtitle { font-size: .875rem; color: var(--text-muted); margin: 0; }

.uc-toolbar {
    display: flex; align-items: center; gap: .75rem;
    margin-bottom: 1rem; flex-wrap: wrap;
}
.uc-search {
    flex: 1; min-width: 200px; padding: .45rem .75rem;
    background: var(--bg-input); border: 1px solid var(--border);
    border-radius: 6px; color: var(--text); font-size: .875rem;
}
.uc-filter {
    padding: .45rem .6rem; background: var(--bg-input);
    border: 1px solid var(--border); border-radius: 6px;
    color: var(--text); font-size: .875rem;
}
.uc-count { font-size: .8rem; color: var(--text-muted); white-space: nowrap; }

.uc-loading { padding: 3rem; text-align: center; color: var(--text-muted); }
.uc-alert { padding: .75rem 1rem; border-radius: 8px; font-size: .875rem; }
.uc-alert-error { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.3); color: #fca5a5; }

/* Table */
.table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--border); }

.data-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.data-table thead th {
    padding: .6rem 1rem; text-align: left; font-size: .75rem;
    font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
    color: var(--text-muted); background: var(--bg-surface);
    border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: rgba(255,255,255,.04); }
.data-table tbody td { padding: .65rem 1rem; vertical-align: top; }
.row-inactive { opacity: .55; }

.cell-name  { font-weight: 600; }
.cell-email { font-size: .78rem; color: var(--text-muted); }
.cell-phone { font-size: .75rem; color: var(--text-muted); }
.cell-muted { color: var(--text-muted); font-size: .82rem; }

/* Badges */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 9999px; font-size: .72rem; font-weight: 600; }
.badge-active    { background: rgba(34,197,94,.15);  color: #4ade80; }
.badge-inactive  { background: rgba(100,116,139,.15); color: #94a3b8; }
.badge-trial     { background: rgba(251,191,36,.15);  color: #fbbf24; }
.badge-pending   { background: rgba(251,191,36,.15);  color: #fbbf24; }
.badge-suspended { background: rgba(239,68,68,.15);   color: #f87171; }
.badge-type      { background: rgba(99,102,241,.15);  color: #a5b4fc; }
.badge-sub       { margin-left: .3rem; }

/* Action button */
.btn-action {
    padding: .3rem .75rem; background: transparent;
    border: 1px solid var(--border); border-radius: 6px;
    color: var(--text-muted); font-size: .8rem; cursor: pointer;
    white-space: nowrap; transition: all .15s;
}
.btn-action:hover { border-color: var(--primary); color: var(--primary); }

/* Empty */
.empty-state { text-align: center; padding: 2.5rem; color: var(--text-muted); font-size: .875rem; }

/* ── Action Modal ──────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.55);
    z-index: 100; animation: fadeIn .15s;
}
.modal-panel {
    position: fixed; top: 50%; right: 0; transform: translateY(-50%);
    width: 380px; max-width: 95vw; max-height: 90vh; overflow-y: auto;
    background: var(--bg-surface); border: 1px solid var(--border);
    border-radius: 12px 0 0 12px; z-index: 101;
    box-shadow: -8px 0 40px rgba(0,0,0,.4);
    animation: slideIn .2s ease;
}
@keyframes slideIn { from { transform: translateY(-50%) translateX(100%); } to { transform: translateY(-50%) translateX(0); } }
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }

.modal-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    padding: 1.25rem 1.25rem .75rem; border-bottom: 1px solid var(--border);
}
.modal-title  { font-size: 1rem; font-weight: 700; }
.modal-sub    { font-size: .78rem; color: var(--text-muted); margin-top: .1rem; }
.modal-close  { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1rem; padding: .2rem .4rem; border-radius: 4px; }
.modal-close:hover { color: var(--text); background: rgba(255,255,255,.06); }
.modal-body   { padding: 1rem 1.25rem 1.5rem; }

.action-section       { margin-bottom: 1.25rem; }
.action-section-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); margin: 0 0 .6rem; }
.action-row  { display: flex; align-items: center; justify-content: space-between; gap: 1rem; font-size: .875rem; }

.btn-action-modal {
    padding: .35rem .9rem; border-radius: 6px; font-size: .8rem;
    font-weight: 600; cursor: pointer; border: none; transition: opacity .15s;
}
.btn-action-modal:hover { opacity: .85; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: #16a34a; color: #fff; }
.btn-warn    { background: #b45309; color: #fff; }

.action-pills { display: flex; flex-wrap: wrap; gap: .5rem; }
.pill {
    padding: .3rem .8rem; border-radius: 9999px; font-size: .8rem;
    background: rgba(255,255,255,.06); border: 1px solid var(--border);
    color: var(--text); cursor: pointer; transition: all .15s;
}
.pill:hover { background: rgba(255,255,255,.1); border-color: var(--primary-text); }
.pill-danger { border-color: rgba(239,68,68,.4); color: #f87171; }
.pill-danger:hover { background: rgba(239,68,68,.12); }
.pill-active { background: var(--primary); border-color: transparent; color: #fff; }
.pill-active:hover { background: var(--primary); }

.action-feedback {
    margin-top: 1rem; padding: .6rem .8rem; border-radius: 6px;
    font-size: .82rem;
}
.action-feedback-ok  { background: rgba(34,197,94,.12);  color: #4ade80; }
.action-feedback-err { background: rgba(251,191,36,.12); color: #fbbf24; }

/* ── Course Builder ──────────────────────────────────────────────────────── */
.cb-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 10px; padding: 1.25rem 1.5rem;
}
.cb-result {
    background: rgba(99,102,241,.06); border: 1px solid rgba(99,102,241,.2);
    border-radius: 8px; padding: 1rem 1.2rem;
}
.badge-green { display:inline-block; padding:.15rem .55rem; border-radius:9999px; font-size:.72rem; font-weight:600; background:rgba(34,197,94,.15); color:#4ade80; }
.badge-amber { display:inline-block; padding:.15rem .55rem; border-radius:9999px; font-size:.72rem; font-weight:600; background:rgba(245,158,11,.15); color:#fbbf24; }
.tag { display:inline-block; margin:2px 4px 2px 0; padding:.15rem .5rem; border-radius:6px; font-size:.75rem; background:rgba(255,255,255,.07); border:1px solid var(--border); color:var(--text-secondary); }
.uc-alert-success { background:rgba(34,197,94,.12); border:1px solid rgba(34,197,94,.3); color:#4ade80; }
.uc-btn-primary { background:var(--primary); color:#fff; border-color:transparent; }
.uc-btn-success { background:#15803d; color:#fff; border-color:transparent; }
.uc-btn-warn    { background:#b45309; color:#fff; border-color:transparent; }
.uc-btn-danger  { background:#b91c1c; color:#fff; border-color:transparent; }
.uc-btn-sm      { padding:.2rem .55rem; font-size:.75rem; }
.uc-input { width:100%; padding:.45rem .65rem; background:var(--surface-alt,rgba(255,255,255,.05)); border:1px solid var(--border); border-radius:6px; color:var(--text); font-size:.875rem; box-sizing:border-box; }
.uc-label { display:block; font-size:.78rem; color:var(--text-secondary); margin-bottom:3px; }
.sc-modal-backdrop { position:fixed; inset:0; background:rgba(0,0,0,.55); display:flex; align-items:center; justify-content:center; z-index:999; }
.sc-modal { background:var(--surface); border:1px solid var(--border); border-radius:10px; padding:1.5rem 2rem; min-width:300px; }
