/* 
 * Yiion Unified Admin Pro - State of the Art v3.0
 * Premium Design System: Glassmorphism + Dynamic Motion + Depth
 */

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

:root {
    /* --- Premium Color Palette (Light) --- */
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --primary-glow: rgba(99, 102, 241, 0.25);
    
    --accent: #f43f5e;
    --accent-glow: rgba(244, 63, 94, 0.2);
    
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #0ea5e9;

    --bg-app: #f1f5f9;
    --bg-sidebar: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    --bg-content: #ffffff;
    --bg-card: #ffffff;
    --bg-header: rgba(255, 255, 255, 0.8);
    --bg-input: #f8fafc;
    
    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-inverse: #ffffff;
    
    --border: #e2e8f0;
    --border-light: rgba(99, 102, 241, 0.1);
    
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 30px;
    
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.05);
    --shadow-md: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.05);
    --shadow-lg: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
    --shadow-glow: 0 0 20px var(--primary-glow);
    
    --sidebar-width: 240px;
    --header-height: 70px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.dark-mode {
    /* --- Premium Color Palette (Dark) --- */
    --bg-app: #030712;
    --bg-sidebar: linear-gradient(135deg, #020617 0%, #0f172a 100%);
    --bg-content: #030712;
    --bg-card: #0f172a;
    --bg-header: rgba(15, 23, 42, 0.8);
    --bg-input: rgba(30, 41, 59, 0.5);
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    --border: rgba(255, 255, 255, 0.08);
    --border-light: rgba(99, 102, 241, 0.2);
    
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.3);
    --shadow-md: 0 10px 30px rgba(0,0,0,0.5);
    --shadow-lg: 0 20px 40px rgba(0,0,0,0.6);
}

/* --- Base & Reset --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-app);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
    font-size: 0.9rem;
    transition: background 0.5s ease, color 0.5s ease;
}

h1, h2, h3, h4, .logo-text, .nav-label {
    font-family: 'Outfit', sans-serif;
}

button, input, select, textarea {
    font-family: inherit;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* --- Layout Structure --- */
.app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
}

/* --- Sidebar: High Precision --- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: var(--text-inverse);
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 100;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.2);
    transition: var(--transition), width 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-header {
    height: var(--header-height);
    padding: 0 2rem;
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.logo {
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: var(--transition);
}

.logo-icon {
    font-size: 2rem;
    filter: drop-shadow(0 0 12px var(--primary));
    animation: pulse 3s infinite ease-in-out;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); filter: drop-shadow(0 0 8px var(--primary)); }
    50% { transform: scale(1.1); filter: drop-shadow(0 0 20px var(--primary)); }
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 900;
    letter-spacing: -0.03rem;
    background: linear-gradient(to right, #fff, var(--primary-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-content {
    flex: 1;
    padding: 1.5rem 1rem;
    overflow-y: auto;
    overflow-x: hidden;
}

.nav-group {
    margin-bottom: 2rem;
}

.nav-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.15rem;
    color: rgba(255, 255, 255, 0.3);
    margin-bottom: 1rem;
    padding-left: 0.75rem;
    font-weight: 800;
}

.selector-box {
    margin-bottom: 1.5rem;
    position: relative; /* Ensure it stays in flow */
}

/* --- Premium Custom Dropdown System --- */
.custom-select-wrapper {
    position: relative;
    user-select: none;
    width: 100%;
}

.custom-select {
    position: relative;
    display: flex;
    flex-direction: column;
}

.custom-select-trigger {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    font-size: 0.9rem;
    font-weight: 700;
    color: #fff;
    height: 42px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    backdrop-filter: blur(10px);
}

.custom-select-trigger:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
}

.custom-select-trigger:after {
    content: '';
    width: 12px;
    height: 12px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='white'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
    transition: transform 0.3s ease;
}

.custom-select.open .custom-select-trigger:after {
    transform: rotate(180deg);
}

.custom-options {
    position: absolute;
    display: block;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    min-width: 200px; /* Prevent squashing in sidebar */
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
    z-index: 99999 !important;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto; /* Added scrollbar support */
    max-height: 280px; /* Limit height for long lists */
}

.custom-select.open .custom-options {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.custom-option {
    position: relative;
    display: block;
    padding: 0.85rem 1.25rem;
    font-size: 0.88rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    transition: var(--transition);
}

/* Match internal option highlight corners with the parent container */
.custom-option:first-child {
    border-top-left-radius: calc(var(--radius-md) - 2px);
    border-top-right-radius: calc(var(--radius-md) - 2px);
}

.custom-option:last-child {
    border-bottom-left-radius: calc(var(--radius-md) - 2px);
    border-bottom-right-radius: calc(var(--radius-md) - 2px);
}

.custom-option:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    padding-left: 1.5rem;
}

.custom-option.selected {
    background: var(--primary);
    color: #fff;
}

/* Light Mode Support for Dropdowns */
body:not(.dark-mode) .custom-options {
    background: #ffffff;
    border-color: var(--border);
    box-shadow: var(--shadow-lg);
}

body:not(.dark-mode) .custom-option {
    color: var(--text-main);
}

body:not(.dark-mode) .custom-option:hover {
    background: #f1f5f9;
}

body:not(.dark-mode) .custom-select-trigger {
    background: #fff;
    border-color: var(--border);
    color: var(--text-main);
}

body:not(.dark-mode) .custom-select-trigger:after {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%230f172a'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
}

/* Ensure sidebar doesn't clip the dropdown */
.sidebar {
    overflow: visible !important;
}

.sidebar-content {
    overflow: visible !important;
}

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

.nav-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    color: rgba(255, 255, 255, 0.5);
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.nav-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%) translateX(-100%);
    width: 4px;
    height: 20px;
    background: var(--primary);
    border-radius: 0 4px 4px 0;
    transition: var(--transition);
}

.nav-item:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.03);
    transform: translateX(5px);
}

.nav-item.active {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary-light);
    box-shadow: inset 0 0 20px rgba(99, 102, 241, 0.05);
}

.nav-item.active::before {
    transform: translateY(-50%) translateX(0);
}

.nav-item.active svg {
    color: var(--primary-light);
    filter: drop-shadow(0 0 5px var(--primary-glow));
}

.nav-item svg {
    width: 20px;
    height: 20px;
    stroke-width: 2.2;
    transition: var(--transition);
}

.sidebar-footer {
    padding: 1.25rem 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.03);
    margin-top: auto;
    background: rgba(0, 0, 0, 0.1);
}

/* --- Main Area & Top Nav --- */
.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

.top-nav {
    height: var(--header-height);
    background: var(--bg-header);
    backdrop-filter: blur(15px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 3rem;
    z-index: 50;
    transition: var(--transition);
    position: sticky;
    top: 0;
}

.page-title h1 {
    font-size: 1.5rem;
    font-weight: 850;
    color: var(--text-main);
    letter-spacing: -0.04rem;
}

.page-title p {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 600;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.badge-master {
    background: var(--primary);
    color: #fff;
    padding: 0.5rem 1rem;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05rem;
    box-shadow: 0 4px 15px var(--primary-glow);
}

/* --- Dashboard Views --- */
.content-body {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    background: radial-gradient(circle at top right, rgba(99, 102, 241, 0.03), transparent);
}

.module-view {
    display: none;
    animation: slideUp 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

.module-view.active {
    display: block;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Stats Grid --- */
.stats-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    padding: 1.25rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 100px;
    height: 100px;
    background: linear-gradient(135deg, transparent 50%, rgba(99, 102, 241, 0.03) 100%);
    border-radius: 0 0 0 100%;
}

.stat-card:hover {
    transform: translateY(-8px) scale(1.02);
    border-color: var(--primary-light);
    box-shadow: var(--shadow-lg), 0 0 20px rgba(99, 102, 241, 0.1);
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}

.stat-label {
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1rem;
}

.stat-icon-wrap {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.stat-icon-wrap svg {
    width: 20px;
    height: 20px;
}

.stat-icon-wrap.bg-blue { background: rgba(14, 165, 233, 0.1); color: #0ea5e9; }
.stat-icon-wrap.bg-green { background: rgba(16, 185, 129, 0.1); color: #10b981; }
.stat-icon-wrap.bg-orange { background: rgba(245, 158, 11, 0.1); color: #f59e0b; }
.stat-icon-wrap.bg-red { background: rgba(239, 68, 68, 0.1); color: #ef4444; }
.stat-icon-wrap.bg-indigo { background: rgba(99, 102, 241, 0.1); color: #6366f1; }
.stat-icon-wrap.bg-violet { background: rgba(139, 92, 246, 0.1); color: #8b5cf6; }

.stat-card:hover .stat-icon-wrap {
    background: var(--primary);
    color: #fff;
    transform: rotate(10deg);
}

.stat-value {
    font-size: 2.2rem;
    font-weight: 900;
    color: var(--text-main);
    letter-spacing: -0.1rem;
    margin-top: 0.25rem;
}

/* --- Data Wrapper & Tables --- */
.data-wrapper {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    margin-bottom: 2rem;
}

.data-header {
    padding: 1.50rem 2rem;
    border-bottom: 1px solid var(--border);
    background: rgba(248, 250, 252, 0.5);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.dark-mode .data-header {
    background: rgba(15, 23, 42, 0.5);
}

.data-header h2 {
    font-size: 1.25rem;
    font-weight: 850;
}

.search-wrap {
    position: relative;
    width: 300px;
}

.search-wrap input {
    width: 100%;
    height: 42px;
    padding: 0 1rem 0 2.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-size: 0.88rem;
    font-weight: 500;
    transition: var(--transition);
}

.search-wrap input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-glow);
    background: var(--bg-card);
}

.search-wrap svg {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    color: var(--text-muted);
}

.filter-select {
    width: 100%;
    height: 42px;
    padding: 0 1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-main);
    font-size: 0.9rem;
    font-weight: 600;
    outline: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='currentColor'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1rem;
}

.dark-mode .filter-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='white'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
}

.table-scroller {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

th {
    padding: 1rem 1.5rem;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 800;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08rem;
    background: rgba(248, 250, 252, 0.8);
    border-bottom: 1px solid var(--border);
}

.dark-mode th {
    background: rgba(15, 23, 42, 0.8);
}

td {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
    color: var(--text-main);
    font-weight: 500;
    transition: var(--transition);
}

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

tr:hover td {
    background: rgba(99, 102, 241, 0.02);
}

/* --- Profile Pill --- */
.profile-pill {
    display: flex;
    align-items: center;
}

.p-name {
    display: block;
    font-weight: 800;
    font-size: 0.92rem;
    color: var(--text-main);
}

.p-date {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* --- Professional Badges --- */
.badge {
    padding: 0.4rem 1rem;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.03rem;
}

.badge-success { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.badge-danger { background: rgba(239, 68, 68, 0.1); color: var(--danger); }
.badge-info { background: rgba(14, 165, 233, 0.1); color: var(--info); }

/* --- License Box --- */
.license-box {
    background: var(--bg-input);
    border: 1px solid var(--border);
    padding: 0.5rem 0.85rem;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    font-weight: 700;
    width: fit-content;
}

.copy-icon {
    cursor: pointer;
    color: var(--text-muted);
    transition: var(--transition);
}

.copy-icon:hover {
    color: var(--primary);
    transform: scale(1.2);
}

/* --- Usage Mini --- */
.usage-mini {
    width: 200px;
}

.mini-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    font-weight: 800;
    margin-bottom: 0.6rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.mini-bar {
    height: 8px;
    background: var(--border);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.mini-fill {
    height: 100%;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.3);
}

/* --- Buttons: Premium Feel --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    height: 42px;
    padding: 0 1.25rem;
    border-radius: var(--radius-md);
    border: none;
    font-weight: 800;
    font-size: 0.88rem;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-solid {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 8px 20px -6px var(--primary-glow);
}

.btn-solid:hover {
    background: var(--primary-dark);
    transform: translateY(-3px);
    box-shadow: 0 12px 25px -5px var(--primary-glow);
}

.btn-ghost {
    background: rgba(99, 102, 241, 0.05);
    color: var(--primary);
    border: 1px solid rgba(99, 102, 241, 0.1);
}

.btn-ghost:hover {
    background: var(--primary);
    color: #fff;
    transform: translateY(-3px);
}

.btn-sm {
    padding: 0 1.25rem;
    height: 42px;
    font-size: 0.85rem;
    border-radius: var(--radius-md);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.btn-danger:hover {
    background: var(--danger);
    color: #fff;
    transform: translateY(-3px);
}

/* --- Config Grid / Forms --- */
.config-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.field-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 800;
    margin-bottom: 0.75rem;
    color: var(--text-main);
    text-transform: uppercase;
    letter-spacing: 0.05rem;
}

.field-group input, .field-group select, .field-group textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition);
}

.field-group input:focus, .field-group textarea:focus, .field-group select:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--bg-card);
    box-shadow: 0 0 0 5px var(--primary-glow);
}

.field-group select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='currentColor'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1rem;
    padding-right: 2.5rem !important;
    color-scheme: light dark;
}

.dark-mode .field-group select {
    color-scheme: dark;
}

/* --- Theme Toggle --- */
.theme-toggle {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background: var(--bg-input);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-muted);
}

.theme-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: rotate(15deg) scale(1.1);
}

.theme-toggle svg {
    width: 24px;
    height: 24px;
}

/* --- Overlays & Modals --- */
.overlay {
    position: fixed; inset: 0; background: rgba(2, 6, 23, 0.8); backdrop-filter: blur(12px);
    z-index: 1000; display: none; align-items: center; justify-content: center;
    animation: fadeIn 0.3s ease;
}

.overlay.active { display: flex; }

.modal {
    background: var(--bg-card);
    width: 100%;
    max-width: 600px;
    padding: 3.5rem;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    position: relative;
    transform: scale(0.9);
    animation: zoomIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes zoomIn { to { transform: scale(1); } }

/* --- Auth Layer --- */
.auth-overlay {
    position: fixed; inset: 0; 
    background: radial-gradient(circle at center, rgba(15, 23, 42, 0.9), rgba(2, 6, 23, 1));
    backdrop-filter: blur(20px);
    z-index: 10000; 
    display: none; 
    align-items: center; 
    justify-content: center;
    padding: 1.5rem;
}

.auth-overlay.active { display: flex; }

.auth-container {
    width: 100%;
    max-width: 420px;
    position: relative;
    perspective: 1000px;
}

.auth-card {
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(30px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-xl);
    padding: 3rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    display: none;
    flex-direction: column;
    animation: authFlip 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

.auth-card.active { display: flex; }

@keyframes authFlip {
    from { opacity: 0; transform: rotateY(-15deg) translateY(20px); }
    to { opacity: 1; transform: rotateY(0) translateY(0); }
}

.auth-header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.auth-logo {
    font-size: 3.5rem;
    margin-bottom: 1.5rem;
    filter: drop-shadow(0 0 15px var(--primary-glow));
}

.auth-header h2 {
    font-size: 1.8rem;
    font-weight: 900;
    color: #fff;
    margin-bottom: 0.5rem;
    letter-spacing: -0.05rem;
}

.auth-header p {
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.85rem;
    font-weight: 600;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.auth-field {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.auth-field label {
    font-size: 0.75rem;
    font-weight: 800;
    color: rgba(255, 255, 255, 0.4);
    text-transform: uppercase;
    letter-spacing: 0.05rem;
    padding-left: 0.25rem;
}

.auth-field input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    padding: 0.9rem 1.25rem;
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    transition: var(--transition);
}

.auth-field input:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.2);
}

.auth-actions {
    display: flex;
    justify-content: flex-end;
}

.forgot-link {
    font-size: 0.8rem;
    color: var(--primary-light);
    text-decoration: none;
    font-weight: 700;
    transition: var(--transition);
}

.forgot-link:hover {
    color: #fff;
    text-decoration: underline;
}

.btn-auth {
    width: 100%;
    justify-content: center;
    height: 52px;
    font-size: 1rem;
    margin-top: 0.5rem;
}

.auth-error {
    color: #f43f5e;
    font-size: 0.8rem;
    font-weight: 700;
    text-align: center;
    margin-top: 1rem;
    display: none;
    animation: shake 0.4s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.auth-footer {
    text-align: center;
    margin-top: 2rem;
}

.auth-footer a {
    color: rgba(255, 255, 255, 0.4);
    font-size: 0.85rem;
    font-weight: 700;
    text-decoration: none;
    transition: var(--transition);
}

.auth-footer a:hover {
    color: #fff;
}

.otp-input-group {
    display: flex;
    justify-content: center;
}

.app-container.hidden { display: none !important; }
.auth-overlay.hidden { display: none !important; }

/* --- Data Viewer Overlay (Leads Popup) --- */
.viewer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.85);
    backdrop-filter: blur(12px);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.viewer-overlay.active {
    display: flex;
}

.viewer-win {
    background: var(--bg-card);
    width: 95%;
    max-width: 1100px;
    max-height: 85vh;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg), 0 0 60px rgba(99, 102, 241, 0.15);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0.9);
    animation: zoomIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.viewer-h {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border);
    background: rgba(248, 250, 252, 0.5);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dark-mode .viewer-h {
    background: rgba(15, 23, 42, 0.5);
}

.viewer-h h3 {
    font-size: 1.3rem;
    font-weight: 900;
    color: var(--text-main);
    letter-spacing: -0.03rem;
}

.viewer-h p {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-top: 0.25rem;
}

.viewer-b {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

/* --- Loader --- */
.loader {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

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

/* --- Toast Notification --- */
.toast-msg {
    position: fixed; bottom: 2rem; right: 2rem;
    padding: 1.25rem 2rem;
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    transform: translateX(150%);
    transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 9999;
    display: flex; align-items: center; gap: 1rem;
}

.toast-msg.active { transform: translateX(0); }
.toast-msg.success { border-left: 5px solid var(--success); }
.toast-msg.danger { border-left: 5px solid var(--danger); }

/* --- Premium Pagination System --- */
.pagination-wrap {
    padding: 1.5rem 2.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    background: rgba(248, 250, 252, 0.3);
    border-top: 1px solid var(--border);
}

.dark-mode .pagination-wrap {
    background: rgba(15, 23, 42, 0.2);
}

.page-btn {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-main);
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}

.page-btn:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px var(--primary-glow);
}

.page-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    box-shadow: 0 0 15px var(--primary-glow);
}

.page-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: var(--bg-input);
    pointer-events: none;
}

.page-ellipsis {
    color: var(--text-muted);
    font-weight: 900;
    padding: 0 0.25rem;
    letter-spacing: 0.1rem;
}

/* --- Responsive Adjustments --- */
@media (max-width: 1200px) {
    .sidebar { width: 100px; padding: 0; }
    .logo-text, .nav-item span, .nav-label, .sidebar-footer { display: none; }
    .nav-item { justify-content: center; padding: 1.25rem; }
}

/* --- Close Button for Dynamic Modals --- */
.btn-close-modal {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-muted);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
    transition: var(--transition);
    z-index: 100;
}

.btn-close-modal:hover {
    background: var(--danger);
    color: #fff;
    transform: rotate(90deg) scale(1.1);
}

.dark-mode .btn-close-modal {
    background: rgba(255, 255, 255, 0.05);
}

/* ===========================================
   FOLLOW-UP AUTOMATION
   =========================================== */
.tab-bar {
    display: flex;
    gap: 0.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    margin-bottom: 0;
}
.tab-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    padding: 0.75rem 1.25rem;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: rgba(255, 255, 255, 0.9); }
.tab-btn.active {
    color: var(--accent, #6366f1);
    border-bottom-color: var(--accent, #6366f1);
}

.cadence-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}
.cadence-step {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1rem;
}
.cadence-step h5 {
    margin: 0 0 0.5rem;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent, #6366f1);
}
.cadence-step label {
    display: block;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-top: 0.5rem;
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.03rem;
}

.form-grid label {
    display: block;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.03rem;
}
.toggle-row {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-main);
    font-weight: 600;
    cursor: pointer;
}
.req { color: #f43f5e; }

/* --- Form Rows & Modals --- */
.form-row {
    margin-bottom: 1.25rem;
}

.form-row label {
    display: block;
    font-size: 0.85rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    color: var(--text-main);
    text-transform: uppercase;
    letter-spacing: 0.05rem;
}

.form-row input, .form-row select, .form-row textarea,
.form-grid input, .form-grid select, .form-grid textarea,
.cadence-step input, .cadence-step select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition);
}

.form-row input:focus, .form-row select:focus, .form-row textarea:focus,
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus,
.cadence-step input:focus, .cadence-step select:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--bg-card);
    box-shadow: 0 0 0 5px var(--primary-glow);
}

.form-row select, .form-grid select, .cadence-step select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='currentColor'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1rem;
    padding-right: 2.5rem !important;
}

.dark-mode .form-row select, .dark-mode .form-grid select, .dark-mode .cadence-step select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='white'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
}

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

.rule-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1rem;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 1rem;
    align-items: center;
}
.rule-card .rule-meta {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.55);
}
.rule-card .rule-meta .badge {
    background: rgba(99, 102, 241, 0.12);
    color: #818cf8;
    padding: 0.15rem 0.5rem;
    border-radius: 6px;
    font-weight: 500;
}
.rule-card .rule-meta .badge.muted {
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.5);
}
.rule-card .rule-meta .badge.dry {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
}
.rule-actions {
    display: flex;
    gap: 0.4rem;
    flex-direction: column;
    align-items: flex-end;
}

.tmpl-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    padding: 1rem;
    margin-bottom: 0.75rem;
}
.tmpl-card .tmpl-name { font-weight: 600; margin-bottom: 0.25rem; }
.tmpl-card .tmpl-body {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.75);
    white-space: pre-wrap;
    line-height: 1.4;
}

.status-pill {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}
.status-pill.pending { background: rgba(251, 191, 36, 0.15); color: #fbbf24; }
.status-pill.ready   { background: rgba(99, 102, 241, 0.15); color: #818cf8; }
.status-pill.sent    { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.status-pill.failed  { background: rgba(244, 63, 94, 0.15); color: #f43f5e; }
.status-pill.skipped { background: rgba(255, 255, 255, 0.06); color: rgba(255, 255, 255, 0.55); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }