/* P4 Packing — Stripe-inspired admin/billing UI system
   Classes prefixed sd- (stripe-dashboard). Used by admin portal and customer billing.
   All dimensions on an 8pt grid. Inter for UI text, IBM Plex Mono for code/IDs/numbers. */

/* ===================================================
   Custom Properties
   =================================================== */

:root {
    --sd-bg:            #F6F9FC;
    --sd-surface:       #FFFFFF;
    --sd-border:        rgba(10,37,64,0.08);
    --sd-border-strong: rgba(10,37,64,0.16);
    --sd-text:          #0A2540;
    --sd-text-muted:    #425466;
    --sd-text-subtle:   #6B7C93;
    --sd-accent:        #635BFF;
    --sd-accent-hover:  #5851E5;
    --sd-success:       #30B672;
    --sd-warning:       #E8833A;
    --sd-danger:        #CD3D64;
    --sd-brand:         #0A5FAD;
    --sd-radius:        8px;
    --sd-radius-lg:     12px;
    --sd-shadow-card:   0 1px 2px rgba(10,37,64,0.04), 0 0 0 1px var(--sd-border);
    --sd-shadow-pop:    0 4px 16px rgba(10,37,64,0.12), 0 0 0 1px var(--sd-border);
    --sd-font:          'Inter', system-ui, -apple-system, sans-serif;
    --sd-mono:          'IBM Plex Mono', 'Menlo', 'Consolas', monospace;
}

/* ===================================================
   Base / Page Shell
   =================================================== */

.sd-page {
    min-height: 100vh;
    background: var(--sd-bg);
    font-family: var(--sd-font);
    color: var(--sd-text);
    font-size: 14px;
    line-height: 1.5;
    letter-spacing: -0.01em;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===================================================
   Admin Shell Layout
   =================================================== */

.sd-admin-layout {
    display: flex;
    min-height: 100vh;
    background: var(--sd-bg);
}

/* ── Sidebar ─────────────────────────────────────── */

.sd-sidebar {
    width: 220px;
    background: #fff;
    border-right: 1px solid var(--sd-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sd-sidebar-logo {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--sd-border);
    display: flex;
    align-items: center;
    gap: 0.625rem;
    text-decoration: none;
}

.sd-sidebar-brand {
    font-size: 1rem;
    font-weight: 700;
    color: var(--sd-brand);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.sd-sidebar-brand-sub {
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--sd-text-subtle);
    display: block;
    margin-top: 1px;
}

.sd-sidebar-section {
    padding: 1.25rem 0.75rem 0.5rem;
}

.sd-sidebar-section-label {
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--sd-text-subtle);
    padding: 0 0.5rem;
    margin-bottom: 0.25rem;
    display: block;
}

.sd-sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4375rem 0.5rem;
    border-radius: 6px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--sd-text-muted);
    text-decoration: none;
    transition: all 120ms ease-out;
    width: 100%;
    cursor: pointer;
    background: none;
    border: none;
    text-align: left;
}

.sd-sidebar-link:hover {
    background: var(--sd-bg);
    color: var(--sd-text);
}

.sd-sidebar-link.active {
    background: rgba(99,91,255,0.08);
    color: var(--sd-accent);
    font-weight: 600;
}

.sd-sidebar-link svg,
.sd-sidebar-link .sd-sidebar-icon {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    opacity: 0.7;
}

.sd-sidebar-link:hover svg,
.sd-sidebar-link:hover .sd-sidebar-icon {
    opacity: 1;
}

.sd-sidebar-link.active svg,
.sd-sidebar-link.active .sd-sidebar-icon {
    opacity: 1;
}

.sd-sidebar-footer {
    margin-top: auto;
    padding: 1rem;
    border-top: 1px solid var(--sd-border);
}

/* ── Main content area ───────────────────────────── */

.sd-main {
    flex: 1;
    overflow-x: hidden;
    min-width: 0;
}

.sd-topbar {
    background: #fff;
    border-bottom: 1px solid var(--sd-border);
    padding: 0 1.5rem;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 10;
}

.sd-topbar-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--sd-text);
}

.sd-topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sd-content {
    padding: 1.5rem;
    max-width: 1280px;
}

/* ===================================================
   Page Header
   =================================================== */

.sd-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.sd-page-header-text {
    flex: 1;
    min-width: 0;
}

.sd-page-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--sd-text);
    margin: 0;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.sd-page-subtitle {
    font-size: 0.8125rem;
    color: var(--sd-text-muted);
    margin-top: 0.25rem;
    margin-bottom: 0;
}

.sd-breadcrumb {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.75rem;
    color: var(--sd-text-subtle);
    text-decoration: none;
    margin-bottom: 0.5rem;
    transition: color 120ms;
}

.sd-breadcrumb:hover {
    color: var(--sd-text-muted);
}

.sd-breadcrumb-sep {
    color: var(--sd-border-strong);
}

/* ===================================================
   Cards
   =================================================== */

.sd-card {
    background: var(--sd-surface);
    border: 1px solid var(--sd-border);
    border-radius: var(--sd-radius);
    box-shadow: var(--sd-shadow-card);
}

.sd-card-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--sd-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.sd-card-title {
    font-size: 0.8125rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--sd-text-muted);
    margin: 0;
}

.sd-card-body {
    padding: 1.5rem;
}

.sd-card-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--sd-border);
    background: var(--sd-bg);
    border-radius: 0 0 var(--sd-radius) var(--sd-radius);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

/* ===================================================
   Stat Cards
   =================================================== */

.sd-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.sd-stat-card {
    background: var(--sd-surface);
    border: 1px solid var(--sd-border);
    border-radius: var(--sd-radius);
    box-shadow: var(--sd-shadow-card);
    padding: 1.25rem 1.5rem;
    position: relative;
    overflow: hidden;
    transition: box-shadow 120ms ease-out, border-color 120ms ease-out;
}

.sd-stat-card:hover {
    box-shadow: var(--sd-shadow-pop);
    border-color: var(--sd-border-strong);
}

.sd-stat-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--sd-text-subtle);
    margin: 0 0 0.25rem;
}

.sd-stat-value {
    font-size: 2rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--sd-text);
    line-height: 1.2;
    margin: 0.25rem 0;
    letter-spacing: -0.02em;
}

.sd-stat-meta {
    font-size: 0.75rem;
    color: var(--sd-text-subtle);
    margin-top: 0.25rem;
}

.sd-stat-delta {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 2px 6px;
    border-radius: 12px;
}

.sd-stat-delta.up {
    background: rgba(48,182,114,0.1);
    color: #1a7a4a;
}

.sd-stat-delta.down {
    background: rgba(205,61,100,0.1);
    color: #a0203d;
}

.sd-stat-delta.neutral {
    background: rgba(107,124,147,0.1);
    color: var(--sd-text-muted);
}

/* ===================================================
   Tables
   =================================================== */

.sd-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.sd-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.sd-table thead th {
    padding: 0 1rem 0.5rem;
    text-align: left;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--sd-text-subtle);
    border-bottom: 1px solid var(--sd-border);
    white-space: nowrap;
}

.sd-table thead th:first-child { padding-left: 1.5rem; }
.sd-table thead th:last-child  { padding-right: 1.5rem; }

.sd-table tbody td {
    padding: 0 1rem;
    height: 44px;
    border-bottom: 1px solid var(--sd-border);
    vertical-align: middle;
    color: var(--sd-text);
}

.sd-table tbody td:first-child { padding-left: 1.5rem; }
.sd-table tbody td:last-child  { padding-right: 1.5rem; }

.sd-table tbody tr:last-child td {
    border-bottom: none;
}

.sd-table tbody tr:hover td {
    background: var(--sd-bg);
}

.sd-table tbody tr {
    transition: background 80ms ease-out;
}

.sd-table a {
    color: var(--sd-text);
    text-decoration: none;
}

.sd-table a:hover {
    color: var(--sd-accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.sd-table-num {
    font-variant-numeric: tabular-nums;
    font-family: var(--sd-mono);
    font-size: 0.75rem;
}

/* ===================================================
   Status Badges
   =================================================== */

.sd-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
    line-height: 1.4;
}

/* Green — succeeded, paid, active */
.sd-badge-active,
.sd-badge-succeeded,
.sd-badge-paid {
    background: rgba(48,182,114,0.12);
    color: #0d6638;
    border: 1px solid rgba(48,182,114,0.3);
}

/* Red — failed, past_due, bounced */
.sd-badge-past_due,
.sd-badge-failed,
.sd-badge-bounced {
    background: rgba(205,61,100,0.1);
    color: #a0203d;
    border: 1px solid rgba(205,61,100,0.25);
}

/* Orange — open, pending, queued */
.sd-badge-open,
.sd-badge-pending,
.sd-badge-queued {
    background: rgba(232,131,58,0.1);
    color: #8c4a12;
    border: 1px solid rgba(232,131,58,0.3);
}

/* Gray — canceled, closed, neutral */
.sd-badge-canceled,
.sd-badge-closed,
.sd-badge-neutral {
    background: rgba(66,84,102,0.08);
    color: #425466;
    border: 1px solid rgba(66,84,102,0.18);
}

/* Purple/blue — in_progress, sent, info */
.sd-badge-in_progress,
.sd-badge-sent,
.sd-badge-info {
    background: rgba(99,91,255,0.1);
    color: #3730a3;
    border: 1px solid rgba(99,91,255,0.25);
}

/* P4 Blue — resolved, delivered */
.sd-badge-resolved,
.sd-badge-delivered {
    background: rgba(10,95,173,0.1);
    color: #0a5fad;
    border: 1px solid rgba(10,95,173,0.25);
}

/* ===================================================
   Buttons
   =================================================== */

.sd-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.4375rem 0.875rem;
    border-radius: var(--sd-radius);
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1;
    cursor: pointer;
    transition: all 120ms ease-out;
    border: 1px solid transparent;
    text-decoration: none;
    white-space: nowrap;
    font-family: var(--sd-font);
    letter-spacing: -0.01em;
    vertical-align: middle;
    user-select: none;
}

.sd-btn:focus-visible {
    outline: 2px solid var(--sd-accent);
    outline-offset: 2px;
}

.sd-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.sd-btn-primary {
    background: var(--sd-accent);
    color: #fff;
    border-color: var(--sd-accent);
}

.sd-btn-primary:hover:not(:disabled) {
    background: var(--sd-accent-hover);
    border-color: var(--sd-accent-hover);
    text-decoration: none;
    color: #fff;
}

.sd-btn-secondary {
    background: #fff;
    color: var(--sd-text);
    border-color: var(--sd-border-strong);
}

.sd-btn-secondary:hover:not(:disabled) {
    background: var(--sd-bg);
    color: var(--sd-text);
    text-decoration: none;
}

.sd-btn-ghost {
    background: transparent;
    color: var(--sd-text-muted);
    border-color: transparent;
}

.sd-btn-ghost:hover:not(:disabled) {
    background: var(--sd-bg);
    color: var(--sd-text);
    text-decoration: none;
}

.sd-btn-danger {
    background: var(--sd-danger);
    color: #fff;
    border-color: var(--sd-danger);
}

.sd-btn-danger:hover:not(:disabled) {
    background: #b02854;
    border-color: #b02854;
    text-decoration: none;
    color: #fff;
}

.sd-btn-danger-soft {
    background: rgba(205,61,100,0.08);
    color: var(--sd-danger);
    border-color: rgba(205,61,100,0.25);
}

.sd-btn-danger-soft:hover:not(:disabled) {
    background: var(--sd-danger);
    color: #fff;
    text-decoration: none;
}

.sd-btn-sm {
    padding: 0.3125rem 0.625rem;
    font-size: 0.75rem;
    border-radius: 6px;
}

.sd-btn-lg {
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
}

.sd-btn-icon {
    padding: 0.4375rem;
    width: 32px;
    height: 32px;
    justify-content: center;
}

.sd-btn-icon.sd-btn-sm {
    width: 26px;
    height: 26px;
    padding: 0.25rem;
}

/* ===================================================
   Forms
   =================================================== */

.sd-form-group {
    margin-bottom: 1rem;
}

.sd-form-row {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr 1fr;
}

.sd-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--sd-text-muted);
    margin-bottom: 0.375rem;
}

.sd-label-required::after {
    content: ' *';
    color: var(--sd-danger);
}

.sd-input,
.sd-select,
.sd-textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--sd-border-strong);
    border-radius: var(--sd-radius);
    font-size: 0.8125rem;
    color: var(--sd-text);
    background: #fff;
    outline: none;
    transition: border-color 120ms ease-out, box-shadow 120ms ease-out;
    font-family: var(--sd-font);
    line-height: 1.5;
    -webkit-appearance: none;
}

.sd-input::placeholder,
.sd-textarea::placeholder {
    color: var(--sd-text-subtle);
}

.sd-input:focus,
.sd-select:focus,
.sd-textarea:focus {
    border-color: var(--sd-accent);
    box-shadow: 0 0 0 3px rgba(99,91,255,0.12);
}

.sd-input:disabled,
.sd-select:disabled,
.sd-textarea:disabled {
    background: var(--sd-bg);
    color: var(--sd-text-muted);
    cursor: not-allowed;
}

.sd-textarea {
    resize: vertical;
    min-height: 80px;
}

.sd-select {
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7C93' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.625rem center;
    padding-right: 2rem;
}

.sd-input-hint {
    font-size: 0.6875rem;
    color: var(--sd-text-subtle);
    margin-top: 0.25rem;
}

.sd-input-error {
    border-color: var(--sd-danger) !important;
}

.sd-input-error:focus {
    box-shadow: 0 0 0 3px rgba(205,61,100,0.12) !important;
}

.sd-field-error {
    font-size: 0.6875rem;
    color: var(--sd-danger);
    margin-top: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Search input with magnifier icon */
.sd-search {
    position: relative;
}

.sd-search .sd-input {
    padding-left: 2.25rem;
}

.sd-search::before {
    content: '';
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236B7C93' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'%3E%3C/circle%3E%3Cpath d='m21 21-4.35-4.35'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-size: contain;
    pointer-events: none;
    z-index: 1;
}

/* ===================================================
   Tabs
   =================================================== */

.sd-tabs {
    display: flex;
    border-bottom: 1px solid var(--sd-border);
    gap: 0;
    margin-bottom: 1.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.sd-tabs::-webkit-scrollbar {
    display: none;
}

.sd-tab {
    padding: 0.625rem 1rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--sd-text-muted);
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all 120ms ease-out;
    margin-bottom: -1px;
    text-decoration: none;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    white-space: nowrap;
    font-family: var(--sd-font);
    flex-shrink: 0;
}

.sd-tab:hover {
    color: var(--sd-text);
    text-decoration: none;
}

.sd-tab.active {
    color: var(--sd-accent);
    border-bottom-color: var(--sd-accent);
    font-weight: 600;
}

.sd-tab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    font-size: 0.625rem;
    font-weight: 700;
    background: rgba(66,84,102,0.1);
    color: var(--sd-text-subtle);
    margin-left: 0.375rem;
}

.sd-tab.active .sd-tab-count {
    background: rgba(99,91,255,0.12);
    color: var(--sd-accent);
}

/* ===================================================
   Monospace Code / IDs
   =================================================== */

.sd-code {
    font-family: var(--sd-mono);
    font-size: 0.75rem;
    background: var(--sd-bg);
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    color: var(--sd-text);
    border: 1px solid var(--sd-border);
    word-break: break-all;
}

.sd-copy-wrap {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.sd-copy-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--sd-text-subtle);
    padding: 2px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 120ms ease-out, color 120ms ease-out;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6875rem;
    line-height: 1;
}

.sd-copy-wrap:hover .sd-copy-btn {
    opacity: 1;
}

.sd-copy-btn:hover {
    color: var(--sd-accent);
}

.sd-copy-btn.copied {
    color: var(--sd-success);
    opacity: 1;
}

/* ===================================================
   Empty States
   =================================================== */

.sd-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    text-align: center;
    color: var(--sd-text-muted);
}

.sd-empty-icon {
    width: 40px;
    height: 40px;
    margin-bottom: 1rem;
    color: var(--sd-border-strong);
}

.sd-empty-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--sd-text);
    margin-bottom: 0.5rem;
    margin-top: 0;
}

.sd-empty-text {
    font-size: 0.8125rem;
    max-width: 28rem;
    color: var(--sd-text-muted);
    margin: 0;
}

.sd-empty-action {
    margin-top: 1.25rem;
}

/* ===================================================
   Alerts / Flash Messages
   =================================================== */

.sd-alert {
    padding: 0.75rem 1rem;
    border-radius: var(--sd-radius);
    font-size: 0.8125rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    line-height: 1.5;
}

.sd-alert-icon {
    flex-shrink: 0;
    margin-top: 1px;
}

.sd-alert-success {
    background: rgba(48,182,114,0.1);
    color: #0d6638;
    border: 1px solid rgba(48,182,114,0.3);
}

.sd-alert-error {
    background: rgba(205,61,100,0.1);
    color: #a0203d;
    border: 1px solid rgba(205,61,100,0.25);
}

.sd-alert-warning {
    background: rgba(232,131,58,0.1);
    color: #8c4a12;
    border: 1px solid rgba(232,131,58,0.3);
}

.sd-alert-info {
    background: rgba(99,91,255,0.08);
    color: #3730a3;
    border: 1px solid rgba(99,91,255,0.2);
}

/* ===================================================
   Detail / Info Rows
   =================================================== */

.sd-detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.625rem 0;
    border-bottom: 1px solid var(--sd-border);
    font-size: 0.8125rem;
    gap: 1rem;
}

.sd-detail-row:last-of-type {
    border-bottom: none;
}

.sd-detail-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--sd-text-subtle);
    flex-shrink: 0;
}

.sd-detail-value {
    color: var(--sd-text);
    text-align: right;
}

/* ===================================================
   Pagination
   =================================================== */

.sd-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--sd-border);
    font-size: 0.8125rem;
    color: var(--sd-text-muted);
}

.sd-pagination-count {
    font-size: 0.75rem;
    color: var(--sd-text-subtle);
}

.sd-pagination-btns {
    display: flex;
    gap: 0.25rem;
}

/* ===================================================
   Filters Bar
   =================================================== */

.sd-filters {
    display: flex;
    gap: 0.625rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

.sd-filters-left {
    display: flex;
    gap: 0.625rem;
    align-items: center;
    flex: 1;
    min-width: 0;
}

.sd-filters-right {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-shrink: 0;
}

.sd-filter-select {
    min-width: 140px;
}

.sd-search-input {
    min-width: 200px;
    flex: 1;
}

/* ===================================================
   Section Dividers / Labels
   =================================================== */

.sd-section-label {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--sd-text-subtle);
    margin: 0 0 0.75rem;
}

.sd-divider {
    border: none;
    border-top: 1px solid var(--sd-border);
    margin: 1.5rem 0;
}

/* ===================================================
   Dropdown / Popover menus
   =================================================== */

.sd-dropdown {
    position: relative;
    display: inline-block;
}

.sd-dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 160px;
    background: var(--sd-surface);
    border: 1px solid var(--sd-border);
    border-radius: var(--sd-radius);
    box-shadow: var(--sd-shadow-pop);
    z-index: 100;
    overflow: hidden;
    padding: 0.25rem 0;
}

.sd-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.875rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--sd-text);
    text-decoration: none;
    cursor: pointer;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    transition: background 80ms;
    font-family: var(--sd-font);
}

.sd-dropdown-item:hover {
    background: var(--sd-bg);
    text-decoration: none;
    color: var(--sd-text);
}

.sd-dropdown-item.danger {
    color: var(--sd-danger);
}

.sd-dropdown-item.danger:hover {
    background: rgba(205,61,100,0.06);
}

.sd-dropdown-sep {
    border: none;
    border-top: 1px solid var(--sd-border);
    margin: 0.25rem 0;
}

/* ===================================================
   Avatar / Initials
   =================================================== */

.sd-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(99,91,255,0.1);
    color: var(--sd-accent);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0;
    flex-shrink: 0;
}

.sd-avatar-sm {
    width: 24px;
    height: 24px;
    font-size: 0.625rem;
}

.sd-avatar-lg {
    width: 40px;
    height: 40px;
    font-size: 0.875rem;
}

/* ===================================================
   Loading / Skeleton
   =================================================== */

.sd-skeleton {
    background: linear-gradient(90deg, var(--sd-border) 25%, rgba(10,37,64,0.04) 50%, var(--sd-border) 75%);
    background-size: 200% 100%;
    animation: sd-shimmer 1.4s ease-in-out infinite;
    border-radius: 4px;
}

@keyframes sd-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.sd-skeleton-text {
    height: 12px;
    margin-bottom: 0.5rem;
    border-radius: 3px;
}

.sd-skeleton-text:last-child {
    width: 70%;
}

/* ===================================================
   Modals / Dialogs
   =================================================== */

.sd-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10,37,64,0.4);
    backdrop-filter: blur(2px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.sd-modal {
    background: var(--sd-surface);
    border: 1px solid var(--sd-border);
    border-radius: var(--sd-radius-lg);
    box-shadow: var(--sd-shadow-pop);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
}

.sd-modal-lg {
    max-width: 720px;
}

.sd-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem 1rem;
    border-bottom: 1px solid var(--sd-border);
}

.sd-modal-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--sd-text);
    margin: 0;
    letter-spacing: -0.01em;
}

.sd-modal-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--sd-text-subtle);
    padding: 0.25rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 120ms, background 120ms;
    flex-shrink: 0;
}

.sd-modal-close:hover {
    color: var(--sd-text);
    background: var(--sd-bg);
}

.sd-modal-body {
    padding: 1.25rem 1.5rem;
}

.sd-modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--sd-border);
}

/* ===================================================
   Utility Classes
   =================================================== */

/* Flexbox */
.sd-flex           { display: flex; }
.sd-inline-flex    { display: inline-flex; }
.sd-flex-col       { flex-direction: column; }
.sd-items-center   { align-items: center; }
.sd-items-start    { align-items: flex-start; }
.sd-items-end      { align-items: flex-end; }
.sd-justify-center { justify-content: center; }
.sd-justify-between { justify-content: space-between; }
.sd-justify-end    { justify-content: flex-end; }
.sd-flex-wrap      { flex-wrap: wrap; }
.sd-flex-1         { flex: 1; }
.sd-shrink-0       { flex-shrink: 0; }

/* Gap */
.sd-gap-1 { gap: 0.25rem; }
.sd-gap-2 { gap: 0.5rem; }
.sd-gap-3 { gap: 0.75rem; }
.sd-gap-4 { gap: 1rem; }
.sd-gap-6 { gap: 1.5rem; }

/* Margin */
.sd-mt-2 { margin-top: 0.5rem; }
.sd-mt-3 { margin-top: 0.75rem; }
.sd-mt-4 { margin-top: 1rem; }
.sd-mt-6 { margin-top: 1.5rem; }
.sd-mt-8 { margin-top: 2rem; }
.sd-mb-2 { margin-bottom: 0.5rem; }
.sd-mb-3 { margin-bottom: 0.75rem; }
.sd-mb-4 { margin-bottom: 1rem; }
.sd-mb-6 { margin-bottom: 1.5rem; }
.sd-mb-0 { margin-bottom: 0; }
.sd-ml-auto { margin-left: auto; }
.sd-mr-auto { margin-right: auto; }

/* Typography */
.sd-text-sm     { font-size: 0.8125rem; }
.sd-text-xs     { font-size: 0.75rem; }
.sd-text-2xs    { font-size: 0.6875rem; }
.sd-text-base   { font-size: 0.875rem; }
.sd-text-lg     { font-size: 1rem; }
.sd-text-muted  { color: var(--sd-text-muted); }
.sd-text-subtle { color: var(--sd-text-subtle); }
.sd-text-accent { color: var(--sd-accent); }
.sd-text-danger { color: var(--sd-danger); }
.sd-text-success { color: var(--sd-success); }
.sd-fw-400 { font-weight: 400; }
.sd-fw-500 { font-weight: 500; }
.sd-fw-600 { font-weight: 600; }
.sd-fw-700 { font-weight: 700; }
.sd-mono    { font-family: var(--sd-mono); }
.sd-mono-num { font-variant-numeric: tabular-nums; font-family: var(--sd-mono); }
.sd-uppercase { text-transform: uppercase; letter-spacing: 0.05em; }
.sd-truncate  { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sd-nowrap    { white-space: nowrap; }

/* Display */
.sd-block  { display: block; }
.sd-hidden { display: none; }
.sd-w-full { width: 100%; }

/* Misc */
.sd-rounded    { border-radius: var(--sd-radius); }
.sd-rounded-lg { border-radius: var(--sd-radius-lg); }
.sd-surface    { background: var(--sd-surface); }
.sd-border-box { border: 1px solid var(--sd-border); }

/* ===================================================
   Responsive
   =================================================== */

@media (max-width: 1280px) {
    .sd-stat-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 1024px) {
    .sd-form-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sd-admin-layout {
        flex-direction: column;
    }

    .sd-sidebar {
        width: 100%;
        height: auto;
        position: static;
        border-right: none;
        border-bottom: 1px solid var(--sd-border);
    }

    .sd-sidebar-section {
        padding: 0.5rem;
    }

    /* Horizontal scrolling nav on mobile */
    .sd-sidebar > .sd-sidebar-section {
        display: flex;
        flex-direction: row;
        gap: 2px;
        overflow-x: auto;
        padding: 0.5rem;
        -webkit-overflow-scrolling: touch;
    }

    .sd-sidebar-link {
        white-space: nowrap;
    }

    .sd-content {
        padding: 1rem;
    }

    .sd-page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .sd-stat-grid {
        grid-template-columns: 1fr 1fr;
    }

    .sd-table thead th:not(:first-child):not(:last-child) {
        display: none;
    }

    .sd-modal {
        max-width: 100%;
        border-radius: var(--sd-radius);
    }

    .sd-form-row {
        grid-template-columns: 1fr;
    }

    .sd-filters {
        flex-direction: column;
        align-items: stretch;
    }
}

@media (max-width: 480px) {
    .sd-stat-grid {
        grid-template-columns: 1fr;
    }

    .sd-page-title {
        font-size: 1.25rem;
    }
}

/* ===================================================
   Admin Analytics Dashboard
   =================================================== */

:root {
    --p4-blue:   #0A5FAD;
    --p4-orange: #FBAD48;
}

/* KPI Grid */
.sd-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

/* KPI Card */
.sd-kpi-card {
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    border-left: 3px solid var(--sd-brand);
    transition: box-shadow 0.15s ease;
}
.sd-kpi-card:hover {
    box-shadow: var(--sd-shadow-pop);
}
.sd-kpi-card-link:hover {
    text-decoration: none;
    color: inherit;
}
.sd-kpi-card-accent-blue  { border-left-color: var(--p4-blue);    }
.sd-kpi-card-accent-orange { border-left-color: var(--p4-orange); }
.sd-kpi-card-accent-success { border-left-color: var(--sd-success); }
.sd-kpi-card-accent-danger  { border-left-color: var(--sd-danger);  }

.sd-kpi-body {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.sd-kpi-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--sd-text-subtle);
}

.sd-kpi-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.03em;
    font-family: var(--sd-mono);
    color: var(--sd-text);
}

.sd-kpi-sparkline-row {
    margin: 0.125rem 0;
}

.sd-kpi-delta {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--sd-text-subtle);
}
.sd-kpi-delta.up   { color: var(--sd-success); }
.sd-kpi-delta.down { color: var(--sd-danger);  }

.sd-kpi-extra {
    font-size: 0.7rem;
    color: var(--sd-text-subtle);
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.125rem;
}

.sd-kpi-priority-dot {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 1px 6px;
    border-radius: 10px;
    font-size: 0.68rem;
    font-weight: 600;
    background: rgba(10,37,64,0.05);
}
.sd-kpi-priority-dot.urgent { background: rgba(205,61,100,0.12); color: var(--sd-danger);  }
.sd-kpi-priority-dot.high   { background: rgba(232,131,58,0.12); color: var(--sd-warning); }
.sd-kpi-priority-dot.normal { background: rgba(10,95,173,0.09);  color: var(--sd-brand);   }
.sd-kpi-priority-dot.low    { background: rgba(10,37,64,0.05);   color: var(--sd-text-subtle); }

/* Dashboard Row Layouts */
.sd-dash-row {
    display: grid;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}
.sd-dash-row-full   { grid-template-columns: 1fr; }
.sd-dash-row-1-1    { grid-template-columns: 1fr 1fr; }
.sd-dash-row-1-1-1  { grid-template-columns: 1fr 1fr 1fr; }
.sd-dash-row-2-1    { grid-template-columns: 2fr 1fr; }
.sd-dash-row-3-1    { grid-template-columns: 3fr 1fr; }

/* Chart Panels */
.sd-chart-panel {
    overflow: hidden;
}
.sd-chart-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}
.sd-chart-panel-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--sd-text);
}

/* Range Tabs */
.sd-range-tabs {
    display: inline-flex;
    border: 1px solid var(--sd-border);
    border-radius: 6px;
    overflow: hidden;
}
.sd-range-tab {
    padding: 0.3rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--sd-text-muted);
    text-decoration: none;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.1s;
}
.sd-range-tab:hover {
    background: rgba(10,37,64,0.04);
    color: var(--sd-text);
    text-decoration: none;
}
.sd-range-tab.active {
    background: rgba(10,95,173,0.08);
    color: var(--p4-blue);
    font-weight: 600;
}

/* Sparkline */
.sd-sparkline {
    display: block;
    width: 100%;
    height: 32px;
}

/* Donut Legend */
.sd-donut-legend {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.75rem;
}
.sd-donut-legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    color: var(--sd-text-muted);
}
.sd-donut-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Progress Gauge */
.sd-progress-row {
    display: grid;
    grid-template-columns: 90px 1fr 36px;
    align-items: center;
    gap: 0.625rem;
    margin-bottom: 0.5rem;
}
.sd-progress-label {
    font-size: 0.75rem;
    color: var(--sd-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sd-progress-bar {
    height: 6px;
    background: rgba(10,37,64,0.07);
    border-radius: 999px;
    overflow: hidden;
}
.sd-progress-bar-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.4s ease;
}
.sd-progress-count {
    font-family: var(--sd-mono);
    font-size: 0.75rem;
    color: var(--sd-text-subtle);
    text-align: right;
}

/* Activity Feed */
.sd-activity-feed {
    list-style: none;
    padding: 0;
    margin: 0;
}
.sd-activity-row {
    display: grid;
    grid-template-columns: 12px 1fr auto;
    align-items: start;
    gap: 0.625rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--sd-border);
}
.sd-activity-row:last-child {
    border-bottom: none;
}
.sd-activity-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--sd-text-subtle);
    margin-top: 4px;
    flex-shrink: 0;
}
.sd-activity-dot.audit         { background: var(--sd-accent);   }
.sd-activity-dot.new_org       { background: var(--sd-success);  }
.sd-activity-dot.new_ticket    { background: var(--sd-warning);  }
.sd-activity-dot.webhook_failed { background: var(--sd-danger);  }

.sd-activity-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}
.sd-activity-title {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--sd-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none;
}
a.sd-activity-title:hover {
    color: var(--sd-accent);
    text-decoration: underline;
}
.sd-activity-subtitle {
    font-size: 0.72rem;
    color: var(--sd-text-subtle);
}
.sd-activity-time {
    font-size: 0.72rem;
    white-space: nowrap;
    padding-top: 2px;
}

/* Empty state */
.sd-empty-state {
    text-align: center;
    color: var(--sd-text-subtle);
    font-size: 0.875rem;
    padding: 2rem 0;
}

/* Shimmer skeleton */
@keyframes sd-shimmer {
    0%   { background-position: -400px 0; }
    100% { background-position: 400px 0;  }
}
.sd-skeleton {
    background: linear-gradient(90deg, #eef2f7 0%, #f6f9fc 50%, #eef2f7 100%);
    background-size: 800px 100%;
    animation: sd-shimmer 1.4s ease-in-out infinite;
    border-radius: var(--sd-radius);
}

/* Renewal table styles */
.sd-renewal-date {
    font-family: var(--sd-mono);
    font-size: 0.75rem;
    color: var(--sd-text-subtle);
}
.sd-renewal-amount {
    font-family: var(--sd-mono);
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--sd-text);
}
.sd-churn-risk-count {
    font-size: 0.8125rem;
    color: var(--sd-warning);
    font-weight: 500;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--sd-border);
}

/* Responsive collapse */
@media (max-width: 1024px) {
    .sd-dash-row-2-1,
    .sd-dash-row-3-1 {
        grid-template-columns: 1fr;
    }
}
@media (max-width: 768px) {
    .sd-dash-row-1-1,
    .sd-dash-row-1-1-1 {
        grid-template-columns: 1fr;
    }
    .sd-kpi-grid {
        grid-template-columns: 1fr 1fr;
    }
}
@media (max-width: 480px) {
    .sd-kpi-grid {
        grid-template-columns: 1fr;
    }
}
