/* ==========================================================================
   RenewalHub — High-Fidelity Shadcn Admin UI System
   - Exact design system tokens & spacing scale from shadcn-admin.netlify.app
   - Balanced margins, paddings, Zinc palette, Inter typography, 0.5rem radius scale.
   - Synchronized light & dark themes driven by [data-theme] and [data-bs-theme].
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --radius: 0.5rem; /* 8px Shadcn standard radius */

    /* ---- Light Theme (Shadcn Light Zinc) ---- */
    --background: #f4f4f5;       /* Zinc-100 backdrop */
    --card: #ffffff;             /* Pure white card surface */
    --card-foreground: #09090b;  /* Zinc-950 text */
    --popover: #ffffff;
    --popover-foreground: #09090b;

    --primary: #18181b;          /* Dark zinc primary button */
    --primary-hover: #27272a;
    --primary-foreground: #fafafa; /* Bright white text on primary */

    --secondary: #e4e4e7;        /* Zinc-200 secondary fill */
    --secondary-hover: #d4d4d8;
    --secondary-foreground: #18181b;

    --muted: #f4f4f5;
    --muted-foreground: #71717a; /* Zinc-500 text */

    --accent: #f4f4f5;           /* Hover highlight fill */
    --accent-foreground: #18181b;

    --destructive: #ef4444;      /* Red-500 */
    --destructive-foreground: #ffffff;

    --border: #e4e4e7;           /* Crisp Zinc-200 border */
    --input: #e4e4e7;
    --ring: #18181b;

    /* Status Tokens (Subtle Pill Tint) */
    --status-paid: #10b981;
    --status-paid-bg: #ecfdf5;
    --status-paid-border: #a7f3d0;

    --status-pending: #f59e0b;
    --status-pending-bg: #fffbeb;
    --status-pending-border: #fde68a;

    --status-overdue: #f43f5e;
    --status-overdue-bg: #fff1f2;
    --status-overdue-border: #fecdd3;

    /* Sidebar Variables */
    --sidebar-width: 240px;
    --sidebar-bg: #f4f4f5;
    --sidebar-card-bg: #ffffff;
    --sidebar-border: #e4e4e7;
    --sidebar-text: #52525b;
    --sidebar-text-active: #09090b;
    --sidebar-active-bg: #e4e4e7;

    --navbar-bg: rgba(244, 244, 245, 0.85);
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    /* ---- Dark Theme (Shadcn Dark Zinc) ---- */
    --background: #09090b;       /* Zinc-950 deep midnight */
    --card: #09090b;             /* Pure dark card surface */
    --card-foreground: #fafafa;  /* Zinc-50 text */
    --popover: #09090b;
    --popover-foreground: #fafafa;

    --primary: #fafafa;          /* Light zinc primary button */
    --primary-hover: #f4f4f5;
    --primary-foreground: #09090b; /* Dark text on primary */

    --secondary: #27272a;        /* Zinc-800 secondary fill */
    --secondary-hover: #3f3f46;
    --secondary-foreground: #fafafa;

    --muted: #18181b;
    --muted-foreground: #a1a1aa; /* Zinc-400 text */

    --accent: #27272a;           /* Hover highlight fill */
    --accent-foreground: #fafafa;

    --destructive: #7f1d1d;
    --destructive-foreground: #fafafa;

    --border: #27272a;           /* Thin Zinc-800 border */
    --input: #27272a;
    --ring: #d4d4d8;

    --status-paid: #34d399;
    --status-paid-bg: rgba(52, 211, 153, 0.1);
    --status-paid-border: rgba(52, 211, 153, 0.25);

    --status-pending: #fbbf24;
    --status-pending-bg: rgba(251, 191, 36, 0.1);
    --status-pending-border: rgba(251, 191, 36, 0.25);

    --status-overdue: #fb7185;
    --status-overdue-bg: rgba(251, 113, 133, 0.1);
    --status-overdue-border: rgba(251, 113, 133, 0.25);

    --sidebar-bg: #09090b;
    --sidebar-card-bg: #121215;
    --sidebar-border: #27272a;
    --sidebar-text: #a1a1aa;
    --sidebar-text-active: #ffffff;
    --sidebar-active-bg: #27272a;

    --navbar-bg: rgba(9, 9, 11, 0.85);
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
}

/* ---- Global CSS Reset & Typography ---- */
*, *::before, *::after {
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

html {
    font-size: 14px;
}

body {
    font-family: var(--font-sans);
    background-color: var(--background);
    color: var(--card-foreground);
    min-height: 100vh;
    margin: 0;
    line-height: 1.5;
    letter-spacing: -0.012em;
    transition: background-color 0.2s ease, color 0.2s ease;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-sans);
    font-weight: 700;
    color: var(--card-foreground);
    letter-spacing: -0.025em;
    margin-bottom: 0.5rem;
}

h1 { font-size: 1.65rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1.05rem; }
h5 { font-size: 0.95rem; }
h6 { font-size: 0.85rem; }

a {
    color: inherit;
    text-decoration: none;
    transition: color 0.15s ease;
}
a:hover {
    color: var(--primary-hover);
}

.text-muted { color: var(--muted-foreground) !important; }
.text-secondary { color: var(--muted-foreground) !important; }
.text-primary-emphasis { color: var(--card-foreground) !important; }

/* ---- Bootstrap Overrides to Enforce Shadcn Tokens ---- */
.bg-body-tertiary { background-color: var(--background) !important; }
.bg-primary-subtle { background-color: var(--secondary) !important; }
.text-primary { color: var(--card-foreground) !important; }
.bg-danger-subtle { background-color: var(--status-overdue-bg) !important; }
.text-danger { color: var(--status-overdue) !important; }
.bg-success-subtle { background-color: var(--status-paid-bg) !important; }
.text-success { color: var(--status-paid) !important; }
.bg-info-subtle { background-color: var(--secondary) !important; }
.text-info { color: var(--muted-foreground) !important; }
.bg-warning-subtle { background-color: var(--status-pending-bg) !important; }
.text-warning { color: var(--status-pending) !important; }
.bg-secondary-subtle { background-color: var(--secondary) !important; }
.border-subtle { border-color: var(--border) !important; }

/* ---- Layout Sidebar (Shadcn Sidebar) ---- */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    position: fixed;
    top: 0; left: 0;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    z-index: 1000;
    transition: transform 0.2s ease, background-color 0.2s ease;
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* Shadcn Brand Box Header */
.sidebar-brand-box {
    margin: 0.75rem 0.75rem 0.5rem 0.75rem;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius);
    background-color: var(--sidebar-card-bg);
    border: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: background 0.15s ease;
}
.sidebar-brand-box:hover {
    background-color: var(--sidebar-active-bg);
}

.brand-icon-box {
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    background-color: var(--primary);
    color: var(--primary-foreground);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.sidebar-nav {
    padding: 0.5rem 0.75rem;
    flex-grow: 1;
    overflow-y: auto;
}

.sidebar-section-header {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted-foreground);
    padding: 1rem 0.75rem 0.4rem 0.75rem;
}

.sidebar .nav-link {
    color: var(--sidebar-text) !important;
    border-radius: var(--radius);
    padding: 0.55rem 0.75rem;
    margin-bottom: 0.2rem;
    font-weight: 500;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background-color 0.15s ease, color 0.15s ease;
    box-shadow: none !important;
}
.sidebar .nav-link-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.sidebar .nav-link i {
    font-size: 1.1rem;
    width: 18px;
    text-align: center;
}
.sidebar .nav-link:hover {
    color: var(--sidebar-text-active) !important;
    background-color: var(--sidebar-active-bg) !important;
}
.sidebar .nav-link.active {
    color: var(--sidebar-text-active) !important;
    background-color: var(--sidebar-active-bg) !important;
    font-weight: 600 !important;
}

/* Sidebar Count Badges */
.nav-badge {
    background-color: var(--primary);
    color: var(--primary-foreground);
    font-size: 0.68rem;
    font-weight: 700;
    padding: 0.1rem 0.45rem;
    border-radius: 20px;
}

/* Shadcn User Capsule at Bottom */
.sidebar-user-capsule {
    margin: 0.75rem;
    padding: 0.55rem 0.75rem;
    border-radius: var(--radius);
    border: 1px solid var(--sidebar-border);
    background-color: var(--sidebar-card-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.avatar-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--secondary);
    color: var(--secondary-foreground);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.78rem;
    flex-shrink: 0;
}

/* ---- Main Content & Header Bar ---- */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin 0.2s ease;
}

.navbar-top {
    height: 56px;
    background-color: var(--navbar-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    padding: 0 1.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 999;
}

/* Header Sub-Navigation Tabs */
.header-nav-tabs {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 0.5rem !important;
    margin-left: 0.5rem !important;
}
.header-nav-tab {
    display: inline-block !important;
    padding: 0.35rem 0.85rem !important;
    border-radius: var(--radius) !important;
    font-size: 0.85rem !important;
    font-weight: 500 !important;
    color: var(--muted-foreground) !important;
    text-decoration: none !important;
    transition: color 0.15s ease, background-color 0.15s ease;
}
.header-nav-tab:hover {
    color: var(--card-foreground) !important;
    background-color: var(--secondary-hover) !important;
}
.header-nav-tab.active {
    color: var(--card-foreground) !important;
    font-weight: 600 !important;
    background-color: var(--secondary-hover) !important;
}

/* Cmd+K Quick Search Trigger Button */
.command-search-btn {
    display: inline-flex;
    align-items: center;
    gap: 2rem;
    height: 36px;
    padding: 0 0.85rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background-color: var(--background);
    color: var(--muted-foreground);
    font-size: 0.82rem;
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}
.command-search-btn:hover {
    border-color: var(--ring);
    color: var(--card-foreground);
}
.kbd-badge {
    background-color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.15rem 0.4rem;
    font-size: 0.7rem;
    font-weight: 600;
}

/* ---- Page Container Grid ---- */
.page-container {
    max-width: 1440px;
    width: 100%;
    margin: 0 auto;
    padding: 1.75rem 2rem;
}

/* Sub-header Navigation Pill Bar (Overview | Analytics | Reports | Notifications) */
.subnav-pills {
    display: inline-flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 0.25rem !important;
    background-color: var(--secondary) !important;
    padding: 4px !important;
    border-radius: var(--radius) !important;
    margin-bottom: 1.5rem !important;
    border: 1px solid var(--border) !important;
    white-space: nowrap !important;
}
.subnav-pill {
    display: inline-block !important;
    padding: 0.4rem 0.9rem !important;
    border-radius: calc(var(--radius) - 2px) !important;
    font-size: 0.82rem !important;
    font-weight: 500 !important;
    color: var(--muted-foreground) !important;
    cursor: pointer !important;
    white-space: nowrap !important;
    transition: background 0.15s ease, color 0.15s ease;
}
.subnav-pill:hover {
    color: var(--card-foreground) !important;
}
.subnav-pill.active {
    background-color: var(--card) !important;
    color: var(--card-foreground) !important;
    font-weight: 600 !important;
    box-shadow: var(--shadow-sm) !important;
}

/* ---- Shadcn Cards ---- */
.shadcn-card {
    background-color: var(--card) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius) !important;
    box-shadow: var(--shadow-sm) !important;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    margin-bottom: 1rem;
}
.shadcn-card:hover {
    border-color: var(--border) !important;
}

.card-header-shadcn {
    padding: 1.25rem 1.5rem 0.5rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-title-shadcn {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--muted-foreground);
}
.card-icon-muted {
    color: var(--muted-foreground);
    font-size: 1rem;
}

.card-content-shadcn {
    padding: 0 1.5rem 1.25rem 1.5rem;
}

.stat-value {
    font-size: 1.65rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--card-foreground);
    line-height: 1.2;
    margin-bottom: 0.2rem;
}

.stat-subtext {
    font-size: 0.75rem;
    color: var(--muted-foreground);
}

/* ---- Shadcn Buttons ---- */
.btn {
    border-radius: var(--radius);
    font-weight: 500;
    padding: 0.45rem 1rem;
    font-size: 0.85rem;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn-sm { min-height: 32px; padding: 0.35rem 0.75rem; font-size: 0.78rem; }
.btn-lg { min-height: 44px; padding: 0.65rem 1.35rem; font-size: 0.9rem; }

.btn-primary {
    background-color: var(--primary) !important;
    border-color: var(--primary) !important;
    color: var(--primary-foreground) !important;
    box-shadow: var(--shadow-sm);
}
.btn-primary:hover, .btn-primary:focus, .btn-primary:active {
    background-color: var(--primary-hover) !important;
    border-color: var(--primary-hover) !important;
    color: var(--primary-foreground) !important;
}

.btn-secondary {
    background-color: var(--secondary) !important;
    border-color: var(--border) !important;
    color: var(--secondary-foreground) !important;
}
.btn-secondary:hover, .btn-secondary:focus {
    background-color: var(--secondary-hover) !important;
    border-color: var(--border) !important;
    color: var(--secondary-foreground) !important;
}

.btn-outline {
    background-color: transparent !important;
    border: 1px solid var(--border) !important;
    color: var(--card-foreground) !important;
}
.btn-outline:hover, .btn-outline:focus {
    background-color: var(--accent) !important;
    color: var(--accent-foreground) !important;
}

.btn-ghost {
    background-color: transparent !important;
    border: 1px solid transparent !important;
    color: var(--muted-foreground) !important;
}
.btn-ghost:hover {
    background-color: var(--accent) !important;
    color: var(--accent-foreground) !important;
}

.btn-danger {
    background-color: var(--destructive) !important;
    border-color: var(--destructive) !important;
    color: var(--destructive-foreground) !important;
}
.btn-danger:hover { opacity: 0.9; color: var(--destructive-foreground) !important; }

/* ---- Form Controls ---- */
.form-control, .form-select {
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background-color: var(--background);
    color: var(--card-foreground);
    padding: 0.5rem 0.85rem;
    font-size: 0.85rem;
    min-height: 38px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-control:focus, .form-select:focus {
    border-color: var(--ring);
    box-shadow: 0 0 0 2px var(--secondary-hover);
    background-color: var(--background);
    color: var(--card-foreground);
}
.form-control::placeholder { color: var(--muted-foreground); opacity: 0.7; }
.form-label { font-size: 0.8rem; font-weight: 500; color: var(--card-foreground); margin-bottom: 0.4rem; }
.input-group-text {
    background-color: var(--muted);
    border: 1px solid var(--border);
    color: var(--muted-foreground);
    font-size: 0.85rem;
}

/* ---- Shadcn Tables & Unclipped Dropdowns ---- */
.table-responsive {
    overflow-x: auto;
    overflow-y: visible !important;
    min-height: 260px;
    padding-bottom: 3rem;
}
.shadcn-table {
    width: 100%;
    margin-bottom: 0;
    --bs-table-bg: transparent;
    --bs-table-color: var(--card-foreground);
}
.shadcn-table th {
    background-color: transparent;
    color: var(--muted-foreground);
    font-weight: 500;
    text-transform: none;
    font-size: 0.78rem;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    border-top: none;
}
.shadcn-table td {
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background-color: var(--card);
    color: var(--card-foreground);
    vertical-align: middle;
    font-size: 0.85rem;
}
.shadcn-table tbody tr:hover td {
    background-color: var(--accent);
}

/* Dropdown Menu Unclipping in Tables */
.table-responsive .dropdown-menu {
    z-index: 1050 !important;
    box-shadow: var(--shadow-md) !important;
}

/* ---- Status Pills ---- */
.badge-status-paid, .badge-status-pending, .badge-status-overdue, .badge-status-neutral {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-weight: 500;
    font-size: 0.72rem;
    padding: 0.22rem 0.6rem;
    border-radius: var(--radius);
}
.badge-status-paid {
    background-color: var(--status-paid-bg);
    color: var(--status-paid);
    border: 1px solid var(--status-paid-border);
}
.badge-status-pending {
    background-color: var(--status-pending-bg);
    color: var(--status-pending);
    border: 1px solid var(--status-pending-border);
}
.badge-status-overdue {
    background-color: var(--status-overdue-bg);
    color: var(--status-overdue);
    border: 1px solid var(--status-overdue-border);
}
.badge-status-neutral {
    background-color: var(--secondary);
    color: var(--muted-foreground);
    border: 1px solid var(--border);
}

/* ---- Dropdowns & Modals ---- */
.dropdown-menu {
    border-radius: var(--radius) !important;
    border: 1px solid var(--border) !important;
    background-color: var(--popover) !important;
    box-shadow: var(--shadow-md) !important;
    padding: 0.4rem !important;
    color: var(--popover-foreground);
}
.dropdown-item {
    border-radius: calc(var(--radius) - 2px);
    padding: 0.45rem 0.85rem;
    color: var(--popover-foreground) !important;
    font-size: 0.82rem;
    font-weight: 500;
}
.dropdown-item:hover, .dropdown-item:focus {
    background-color: var(--accent) !important;
    color: var(--accent-foreground) !important;
}

.modal-content {
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    background: var(--popover);
    border: 1px solid var(--border);
    color: var(--popover-foreground);
}
.modal-header, .modal-footer { border-color: var(--border) !important; padding: 1rem 1.5rem !important; }
.modal-body { padding: 1.25rem 1.5rem !important; }

/* ---- Responsive ---- */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.active { transform: translateX(0); }
    .main-content { margin-left: 0 !important; }
    .navbar-top { padding: 0 1rem; }
    .page-container { padding: 1.25rem 1rem; }
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}
.sidebar-backdrop.active { opacity: 1; visibility: visible; }
@media (min-width: 992px) { .sidebar-backdrop { display: none; } }

/* ---- Fractional Spacing Utilities (Bootstrap gap-fillers) ---- */
/* Bootstrap only ships whole-number steps; these fill in .5 increments */
.p-1\.5  { padding:    0.375rem !important; }
.p-2\.5  { padding:    0.625rem !important; }
.p-3\.5  { padding:    0.875rem !important; }
.pt-2\.5 { padding-top:    0.625rem !important; }
.pb-2\.5 { padding-bottom: 0.625rem !important; }
.py-2\.5 { padding-top: 0.625rem !important; padding-bottom: 0.625rem !important; }
.px-2\.5 { padding-left: 0.625rem !important; padding-right: 0.625rem !important; }
.ps-2\.5 { padding-left:  0.625rem !important; }
.pe-2\.5 { padding-right: 0.625rem !important; }

.m-1\.5  { margin:    0.375rem !important; }
.m-2\.5  { margin:    0.625rem !important; }
.mt-2\.5 { margin-top:    0.625rem !important; }
.mb-2\.5 { margin-bottom: 0.625rem !important; }
.my-2\.5 { margin-top: 0.625rem !important; margin-bottom: 0.625rem !important; }
.ms-1\.5 { margin-left:  0.375rem !important; }
.me-1\.5 { margin-right: 0.375rem !important; }
.ms-2\.5 { margin-left:  0.625rem !important; }
.me-2\.5 { margin-right: 0.625rem !important; }

.gap-1\.5 { gap: 0.375rem !important; }
.gap-2\.5 { gap: 0.625rem !important; }
.g-2\.5 { --bs-gutter-x: 0.625rem; --bs-gutter-y: 0.625rem; }

