/* VaydaERP Admin Portal — Complete Styles */
/* CSP: No inline styles. All styles external. */

:root {
    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --bg-sidebar: #0c1222;
    --bg-input: #0f172a;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --border: #334155;
    --radius: 8px;
    --radius-sm: 4px;
    --font-ar: 'Segoe UI', 'Noto Kufi Arabic', sans-serif;
    --sidebar-width: 240px;
}

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

body {
    font-family: var(--font-ar);
    background: var(--bg-dark);
    color: var(--text-primary);
    direction: rtl;
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.6;
}

/* ───────── Admin Shell ───────── */
.admin-shell {
    display: flex;
    min-height: 100vh;
}

/* ───────── Sidebar ───────── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-logo {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

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

.logo-text {
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent);
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.nav-item.active {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent);
    font-weight: 600;
}

.nav-item.disabled {
    opacity: 0.4;
    pointer-events: none;
}

.nav-icon {
    font-size: 1rem;
    width: 1.5rem;
    text-align: center;
}

.sidebar-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
}

.sidebar-user {
    margin-bottom: 0.5rem;
}

.user-name {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
}

.user-email {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.btn-logout-sidebar {
    width: 100%;
    padding: 0.35rem;
    background: transparent;
    border: 1px solid var(--danger);
    color: var(--danger);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.75rem;
    transition: background 0.15s;
}

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

/* ───────── Main Content ───────── */
.main-content {
    flex: 1;
    margin-right: var(--sidebar-width);
    min-height: 100vh;
}

.content-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
}

.content-header h1 {
    font-size: 1.15rem;
    font-weight: 600;
}

.content-body {
    padding: 1.25rem 1.5rem;
}

/* ───────── Login / MFA Pages ───────── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
}

.login-container {
    background: var(--bg-card);
    padding: 2.5rem;
    border-radius: var(--radius);
    width: 100%;
    max-width: 420px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.login-container h1 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
    text-align: center;
}

.login-container .subtitle {
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

/* ───────── Forms ───────── */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.3rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.form-group input,
.form-group select,
.form-control {
    width: 100%;
    padding: 0.6rem 0.85rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-control:focus,
.filter-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.12);
}

.form-row {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    margin-bottom: 1rem;
}

.flex-grow {
    flex: 1;
}

/* ───────── Buttons ───────── */
.btn-primary {
    display: inline-block;
    padding: 0.6rem 1.25rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    cursor: pointer;
    transition: background 0.15s;
    text-align: center;
    text-decoration: none;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-sm {
    padding: 0.4rem 0.9rem;
    font-size: 0.8rem;
}

.btn-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.8rem;
}

.btn-link:hover {
    text-decoration: underline;
}

.btn-logout {
    background: transparent;
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 0.4rem 1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
}

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

/* ───────── Validation ───────── */
.validation-summary {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.25);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.85rem;
    margin-bottom: 1rem;
    color: #fca5a5;
    font-size: 0.8rem;
}

.validation-summary:empty {
    display: none;
}

.alert-success {
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.85rem;
    margin-bottom: 1rem;
    color: #86efac;
    font-size: 0.8rem;
}

/* ───────── Toolbar ───────── */
.toolbar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.search-input {
    padding: 0.5rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.8rem;
    min-width: 180px;
}

.search-sm {
    min-width: 120px;
}

.filter-select {
    padding: 0.5rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.8rem;
}

/* ───────── Data Tables ───────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.data-table th {
    text-align: right;
    padding: 0.5rem 0.6rem;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 0.5rem 0.6rem;
    border-bottom: 1px solid rgba(51, 65, 85, 0.4);
    color: var(--text-primary);
}

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

/* ───────── Pagination ───────── */
.pagination-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.pagination-buttons {
    display: flex;
    gap: 0.5rem;
}

/* ───────── Detail Cards ───────── */
.detail-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
}

.detail-card h3 {
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.detail-item {
    display: block;
}

.detail-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.15rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.detail-value {
    font-size: 0.9rem;
    font-weight: 500;
}

/* ───────── Status Badges ───────── */
.status-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 600;
}

.status-active {
    background: rgba(34, 197, 94, 0.15);
    color: #4ade80;
}

.status-maintenance {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
}

.status-suspended {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
}

.status-closed {
    background: rgba(100, 116, 139, 0.15);
    color: #94a3b8;
}

.action-badge {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    background: rgba(59, 130, 246, 0.12);
    color: var(--accent);
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-family: monospace;
}

/* ───────── Dashboard ───────── */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    margin: 0.25rem 0;
}

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

/* ───────── Utilities ───────── */
.monospace {
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: 0.8rem;
}

.muted {
    color: var(--text-muted);
    font-style: italic;
}

.nowrap {
    white-space: nowrap;
}

.error-msg {
    color: var(--danger);
}

.placeholder-note {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ───────── AG Grid Container ───────── */
.ag-grid-container {
    min-height: 300px;
}

/* ───────── Responsive ───────── */
@media (max-width: 768px) {
    .sidebar {
        display: none;
    }

    .main-content {
        margin-right: 0;
    }

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

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

    .toolbar {
        flex-direction: column;
    }
}

/* ───────── Alerts ───────── */
.alert-danger {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.85rem;
    margin-bottom: 1rem;
    color: #fca5a5;
    font-size: 0.8rem;
}

/* alert-warning: amber/orange semantic. Used by Details.cshtml for
   PlanWarning, override-notice, AdminR5 panel notice, and the new
   StepUpRetryInfo guidance after Step-Up-protected POSTs. The previous
   build was rendering these divs unstyled (invisible on the dark theme),
   which caused operators to miss the post-Step-Up "please confirm again"
   guidance during the v10/v12 reset_password validation attempts —
   diagnosed via [DIAG-StepUpHint] logs in رد كلود #23. */
.alert-warning {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.35);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.85rem;
    margin-bottom: 1rem;
    color: #fcd34d;
    font-size: 0.8rem;
}

/* alert-stepup-retry: stronger visual emphasis for the post-Step-Up retry
   guidance. Larger font, bolder weight, more padding, brighter border —
   so an operator returning from the Step-Up OTP screen cannot miss it.
   Diagnosed in رد كلود #25 after v14 owner test: even with .alert-warning
   styled, the alert was off-screen because the operator was scrolled to
   the form panel. This rule + a JS scroll-into-view helper + a SECOND
   render copy inside the AdminR5 panel together ensure visibility. */
.alert-stepup-retry {
    font-size: 0.95rem;
    font-weight: 600;
    padding: 0.85rem 1rem;
    border-width: 2px;
    line-height: 1.5;
}

/* Brief amber pulse to draw the eye on first render after Step-Up.
   Toggled on by tenant-stepup-retry-scroll.js for ~1.8s then removed. */
@keyframes vayda-stepup-retry-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.45); }
    70%  { box-shadow: 0 0 0 12px rgba(245, 158, 11, 0); }
    100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
}
.alert-stepup-retry--pulse {
    animation: vayda-stepup-retry-pulse 1.6s ease-out 0s 2;
}
@media (prefers-reduced-motion: reduce) {
    .alert-stepup-retry--pulse { animation: none; }
}

.alert.alert-success,
.alert.alert-warning,
.alert.alert-danger {
    margin-bottom: 1rem;
}

/* ───────── Additional Buttons ───────── */
.btn-danger {
    display: inline-block;
    padding: 0.6rem 1.25rem;
    background: var(--danger);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-secondary {
    display: inline-block;
    padding: 0.6rem 1.25rem;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

/* ───────── Admin Forms ───────── */
.admin-form {
    max-width: 600px;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-top: 1rem;
}

.form-group textarea {
    width: 100%;
    padding: 0.6rem 0.85rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: var(--font-ar);
    resize: vertical;
    transition: border-color 0.2s;
}

.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.12);
}

/* ───────── Role Checkboxes ───────── */
.role-checkboxes {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    accent-color: var(--accent);
}

/* ───────── Support Notes ───────── */
.note-warning {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    margin-bottom: 1rem;
    color: #fbbf24;
    font-size: 0.75rem;
}

.note-form {
    margin-bottom: 1.5rem;
}

/* Admin-R5 Phase 2 — Tenant User Invite/Reset action grid */
.invite-action-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-top: 1rem;
}
@media (max-width: 800px) {
    .invite-action-grid { grid-template-columns: 1fr; }
}
.invite-action-form {
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.3);
}
.invite-action-form h4 {
    margin: 0 0 0.5rem 0;
    font-size: 1rem;
}
.invite-action-form .small {
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}
.invite-action-form label {
    display: block;
    margin-top: 0.75rem;
    margin-bottom: 0.25rem;
    font-size: 0.9rem;
}
.invite-action-form .form-control {
    width: 100%;
    box-sizing: border-box;
}
.invite-action-form button {
    margin-top: 0.75rem;
}

.notes-timeline {
    border-top: 1px solid var(--border);
    padding-top: 1rem;
}

.note-entry {
    padding: 0.75rem 0;
    border-bottom: 1px solid rgba(51, 65, 85, 0.3);
}

.note-entry:last-child {
    border-bottom: none;
}

.note-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.3rem;
    font-size: 0.75rem;
}

.note-meta strong {
    color: var(--accent);
}

.note-body {
    font-size: 0.85rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ───────── Usage Table ───────── */
.usage-table th,
.usage-table td {
    text-align: center;
}

.usage-table .num {
    font-variant-numeric: tabular-nums;
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: 0.85rem;
}

/* ───────── Dashboard Enhanced ───────── */
.dashboard-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.dashboard-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.period-toggle {
    display: flex;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-card);
}

.period-btn {
    background: var(--bg-card);
    border: none;
    border-left: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 0.5rem 1.25rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-ar);
    font-weight: 500;
}

.period-btn:first-child {
    border-left: none;
}

.period-btn:hover {
    background: rgba(59, 130, 246, 0.15);
    color: var(--text-primary);
}

.period-btn.active {
    background: var(--accent);
    color: #fff;
}

.dashboard-section {
    margin-bottom: 1.5rem;
}

.stat-card-wide {
    grid-column: span 1;
}

.status-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.5rem;
}

.mini-badge {
    font-size: 0.65rem;
    padding: 0.15rem 0.45rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
}

.badge-active {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
}

.badge-expired {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
}

.badge-suspended {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.badge-banned {
    background: rgba(239, 68, 68, 0.25);
    color: #f87171;
}

.badge-maintenance {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent);
}

.badge-closed {
    background: rgba(100, 116, 139, 0.2);
    color: var(--text-muted);
}

.dashboard-grid-half {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 900px) {
    .dashboard-grid-half {
        grid-template-columns: 1fr;
    }
}

.data-table-compact {
    font-size: 0.8rem;
}

.data-table-compact th,
.data-table-compact td {
    padding: 0.5rem 0.6rem;
}

.data-table-compact a {
    color: var(--accent);
    text-decoration: none;
}

.data-table-compact a:hover {
    text-decoration: underline;
}

/* Metering health states */
.health-healthy {
    border-color: var(--success);
}

.health-degraded {
    border-color: var(--warning);
}

.health-stale {
    border-color: var(--danger);
}

/* ───────── Agent Releases ───────── */
.release-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.release-form-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
}

.release-status {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.release-status-success {
    color: var(--success);
}

.release-status-error {
    color: var(--danger);
}

.release-dev-notice {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    color: #fbbf24;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.release-progress {
    margin-top: 0.75rem;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    height: 24px;
    position: relative;
    overflow: hidden;
}

.release-progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: var(--radius-sm);
    width: 0%;
    transition: width 0.3s ease;
}

.release-progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-primary);
}

.release-notes-row td {
    padding-top: 0 !important;
    font-size: 0.75rem;
}

.btn-ghost {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
}

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

.btn-xs {
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
}