/* ============================================
   SuperNova CRM - Design System & Styles
   ============================================ */

/* --- CSS Variables --- */
:root {
    --bg: #0f1923;
    --bg-card: #172a3a;
    --bg-sidebar: #0d1520;
    --bg-header: #0d1520;
    --blue: #4361ee;
    --blue-hover: #3651de;
    --green: #22c55e;
    --green-bg: rgba(34, 197, 94, 0.12);
    --yellow: #f59e0b;
    --yellow-bg: rgba(245, 158, 11, 0.12);
    --red: #ef4444;
    --red-bg: rgba(239, 68, 68, 0.12);
    --purple: #a855f7;
    --purple-bg: rgba(168, 85, 247, 0.12);
    --blue-bg: rgba(67, 97, 238, 0.12);
    --text: #e8e8e8;
    --text2: #8899aa;
    --text3: #5a6a7a;
    --border: #1e3348;
    --border-hover: #2a4a68;
    --radius-card: 12px;
    --radius-btn: 8px;
    --radius-input: 8px;
    --header-h: 56px;
    --sidebar-w: 220px;
    --sidebar-collapsed-w: 60px;
    --side-panel-w: 420px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --shadow: 0 2px 8px rgba(0,0,0,0.25);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
    --transition: 0.2s ease;
    --bg-hover: rgba(255,255,255,0.04);
    --spring: cubic-bezier(0.16, 1, 0.3, 1);
}

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    touch-action: pan-x pan-y;
}

a {
    color: var(--blue);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

h1, h2, h3, h4 {
    font-weight: 600;
    line-height: 1.3;
}
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.1rem; }

img {
    max-width: 100%;
}

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

/* Firefox scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

/* --- Login Page --- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 48px 40px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    max-width: 400px;
    width: 90%;
    animation: fadeSlideIn 0.5s ease-out;
}

.login-logo img {
    margin-bottom: 16px;
    animation: float 3s ease-in-out infinite;
}

.login-logo h1 {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.login-logo p {
    color: var(--text2);
    margin-bottom: 32px;
}

#telegram-login-widget {
    display: flex;
    justify-content: center;
}

/* --- Telegram "Open in browser" bar --- */
.tg-browser-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 32px;
    background: var(--blue);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}
.tg-browser-link {
    color: #fff !important;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
}
.tg-browser-bar ~ .header { top: 32px; }
.tg-browser-bar ~ .sidebar { top: calc(var(--header-h) + 32px); height: calc(100vh - var(--header-h) - 32px); }
.tg-browser-bar ~ .sidebar-overlay { top: calc(var(--header-h) + 32px); }
.tg-browser-bar ~ .content { margin-top: calc(var(--header-h) + 32px); height: calc(100vh - var(--header-h) - 32px); }

/* --- Header --- */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-h);
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    gap: 8px;
    z-index: 100;
    overflow: hidden;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex-shrink: 0;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-logo-text {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
}

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex-shrink: 0;
    justify-content: flex-end;
}

.user-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.3;
}

.user-name {
    font-weight: 600;
    font-size: 0.875rem;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text2);
    text-transform: capitalize;
}

.btn-logout {
    color: var(--text2);
    padding: 6px;
    border-radius: var(--radius-btn);
}
.btn-logout:hover {
    color: var(--red);
    background: var(--red-bg);
}

/* Burger */
.burger-btn {
    display: none;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-btn);
}
.burger-btn span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text);
    border-radius: 1px;
    transition: var(--transition);
}
.burger-btn:hover {
    background: rgba(255,255,255,0.05);
}

/* Rates Widget */
.rates-widget {
    display: flex;
    gap: 16px;
    font-size: 0.825rem;
    color: var(--text2);
}

.rate-item {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.rate-label {
    color: var(--text3);
    font-weight: 500;
}

.rate-value {
    color: var(--text);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* --- Sidebar --- */
.sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 90;
    transition: width var(--transition), transform var(--transition);
}

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

.nav-section-title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text3);
    padding: 16px 16px 6px;
    margin-top: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-btn);
    color: var(--text2);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: background var(--transition), color var(--transition), padding-left var(--transition);
    white-space: nowrap;
    overflow: hidden;
    position: relative;
}

.nav-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    width: 3px;
    height: 0;
    background: var(--blue);
    transition: height 0.2s, top 0.2s;
    border-radius: 0 3px 3px 0;
}

.nav-item.active::before {
    height: 60%;
    top: 20%;
}

.nav-item:hover .nav-icon {
    transform: scale(1.15);
}

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

.nav-item.active {
    background: var(--blue-bg);
    color: var(--blue);
}

.nav-item.active .nav-icon {
    stroke: var(--blue);
}

.nav-icon {
    flex-shrink: 0;
    transition: transform 0.2s;
}

.nav-text {
    transition: opacity var(--transition);
}

.nav-item[style*="display: none"] {
    display: none !important;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 85;
}

/* --- Content Area --- */
.content {
    margin-left: var(--sidebar-w);
    margin-top: var(--header-h);
    padding: 24px;
    height: calc(100vh - var(--header-h));
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    transition: margin-left var(--transition);
}

.content > * {
    animation: fadeSlideIn 0.3s ease-out;
}

/* --- Sub-tabs --- */
.sub-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.sub-tab {
    padding: 10px 18px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text2);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.2s, border-color 0.3s, background 0.2s;
}
.sub-tab:hover:not(.active) {
    color: var(--text);
    background: rgba(67,97,238,0.05);
}
.sub-tab:hover { color: var(--text); }
.sub-tab.active {
    color: var(--blue);
    border-bottom-color: var(--blue);
}
/* sub-content: first child visible, rest hidden via inline style in JS */

/* --- Week/Month Navigation --- */
.week-nav {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}
.week-nav-label {
    font-size: 14px;
    font-weight: 600;
    min-width: 180px;
    text-align: center;
}
.week-nav-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-btn);
    color: var(--text);
    padding: 6px 12px;
    cursor: pointer;
    font-size: 13px;
}
.week-nav-btn:hover { border-color: var(--blue); }

/* --- Calendar Grid --- */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}
.calendar-header-cell {
    text-align: center;
    font-size: 11px;
    color: var(--text2);
    padding: 6px 0;
    text-transform: uppercase;
}
.calendar-cell {
    background: var(--bg-card);
    border-radius: 6px;
    min-height: 60px;
    padding: 6px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: border-color 0.2s;
}
.calendar-cell:hover { border-color: var(--border-hover); }
.calendar-cell.today { border-color: var(--blue); }
.calendar-cell.other-month { opacity: 0.3; }
.calendar-day { font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.calendar-badge {
    background: var(--blue-bg);
    color: var(--blue);
    font-size: 10px;
    font-weight: 600;
    border-radius: 4px;
    padding: 1px 5px;
    display: inline-block;
}

/* --- Distribution Panels --- */
.distrib-panels {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.distrib-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 16px;
}
.distrib-panel h4 {
    margin: 0 0 12px;
    font-size: 14px;
    font-weight: 600;
}
.distrib-panel .field { margin-bottom: 10px; }
.distrib-panel .field label {
    display: block;
    font-size: 11px;
    color: var(--text2);
    margin-bottom: 4px;
}

/* --- Page Header --- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h1 {
    font-size: 1.5rem;
}

.page-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* --- Stat Cards Grid --- */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}
.stat-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.stat-card-label {
    font-size: 0.8rem;
    color: var(--text2);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stat-card-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.stat-card-sub {
    font-size: 0.8rem;
    color: var(--text2);
}

.stat-card-change {
    font-size: 0.8rem;
    font-weight: 600;
}
.stat-card-change.positive { color: var(--green); }
.stat-card-change.negative { color: var(--red); }

.stat-card.clickable {
    cursor: pointer;
}
.stat-card.clickable:hover {
    border-color: var(--blue);
    box-shadow: 0 8px 24px rgba(67,97,238,0.15);
}

/* --- Alert Cards --- */
.alert-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.alert-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    cursor: pointer;
    transition: border-color var(--transition);
}
.alert-card:hover {
    border-color: var(--border-hover);
}

.alert-card-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.alert-card-text {
    flex: 1;
}

.alert-card-title {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 2px;
}

.alert-card-desc {
    font-size: 0.8rem;
    color: var(--text2);
}

.alert-card.alert-warning {
    border-left: 3px solid var(--yellow);
}
.alert-card.alert-danger {
    border-left: 3px solid var(--red);
}
.alert-card.alert-info {
    border-left: 3px solid var(--blue);
}

/* --- Tables --- */
.table-wrapper {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    overflow: hidden;
    margin-bottom: 24px;
}

.table-scroll {
    overflow-x: auto;
}

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

thead {
    position: sticky;
    top: 0;
    z-index: 5;
}

thead th {
    background: rgba(13, 21, 32, 0.95);
    padding: 12px 14px;
    text-align: left;
    font-weight: 600;
    color: var(--text2);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    cursor: default;
    user-select: none;
}

thead th.sortable {
    cursor: pointer;
}
thead th.sortable:hover {
    color: var(--text);
}

thead th .sort-icon {
    display: inline-block;
    margin-left: 4px;
    opacity: 0.3;
    font-size: 0.7rem;
}
thead th.sort-asc .sort-icon,
thead th.sort-desc .sort-icon {
    opacity: 1;
    color: var(--blue);
}

tbody tr {
    border-bottom: 1px solid rgba(30, 51, 72, 0.5);
    transition: background 0.15s, box-shadow 0.15s;
}

tbody tr:hover {
    background: var(--bg-hover);
    box-shadow: inset 3px 0 0 var(--blue);
}

tbody tr.clickable {
    cursor: pointer;
}
tbody tr.clickable:hover {
    background: rgba(67, 97, 238, 0.06);
}

tbody td {
    padding: 10px 14px;
    vertical-align: middle;
    white-space: nowrap;
}

tbody td.wrap {
    white-space: normal;
    max-width: 250px;
}

.table-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--text2);
}

/* Checkbox in table */
.row-checkbox {
    width: 16px;
    height: 16px;
    accent-color: var(--blue);
    cursor: pointer;
}

/* --- Badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    transition: transform 0.15s;
}

.badge:hover {
    transform: scale(1.05);
}

.badge-green {
    background: var(--green-bg);
    color: var(--green);
}
.badge-yellow {
    background: var(--yellow-bg);
    color: var(--yellow);
}
.badge-red {
    background: var(--red-bg);
    color: var(--red);
}
.badge-blue {
    background: var(--blue-bg);
    color: var(--blue);
}
.badge-purple {
    background: var(--purple-bg);
    color: var(--purple);
}
.badge-gray {
    background: rgba(136, 153, 170, 0.12);
    color: var(--text2);
}

/* --- Buttons --- */
button, .btn {
    font-family: var(--font);
    font-size: 0.85rem;
    cursor: pointer;
    border: none;
    outline: none;
    transition: all var(--transition);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-btn);
    font-weight: 500;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(67,97,238,0.3);
}

.btn:active {
    transform: translateY(1px);
    box-shadow: none;
}

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

.btn-secondary {
    background: rgba(255,255,255,0.06);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover {
    background: rgba(255,255,255,0.1);
    border-color: var(--border-hover);
}

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

.btn-ghost {
    background: transparent;
    color: var(--text2);
    border: none;
}
.btn-ghost:hover {
    background: rgba(255,255,255,0.06);
    color: var(--text);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.78rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn.loading {
    opacity: 0.7;
    cursor: not-allowed;
    pointer-events: none;
    position: relative;
}

.btn.loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
    animation: btnShimmer 1.5s infinite;
}

.btn.loading::before {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: 6px;
}

/* --- Inputs & Selects --- */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.form-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text2);
}

input[type="text"],
input[type="search"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="email"],
input[type="tel"],
textarea,
select {
    font-family: var(--font);
    font-size: 0.85rem;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-input);
    padding: 8px 12px;
    outline: none;
    transition: border-color var(--transition);
    width: 100%;
}

/* Date/time picker styling for dark theme */
input[type="date"],
input[type="time"] {
    cursor: pointer;
    position: relative;
    min-height: 36px;
}
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
    filter: invert(0.7);
    cursor: pointer;
    padding: 4px;
    margin: 0;
}
/* Firefox */
input[type="date"]::-moz-calendar-picker-indicator,
input[type="time"]::-moz-calendar-picker-indicator {
    filter: invert(0.7);
}
/* Color scheme for dark mode picker popup */
input[type="date"],
input[type="time"] {
    color-scheme: dark;
}

input:focus, textarea:focus, select:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(67,97,238,0.15);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input::placeholder, textarea::placeholder {
    color: var(--text3);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%238899aa' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

/* Inline edit */
.inline-edit {
    background: transparent;
    border: 1px solid transparent;
    padding: 4px 6px;
    border-radius: 4px;
    color: var(--text);
    width: 100%;
    min-width: 80px;
}
.inline-edit:hover {
    border-color: var(--border);
}
.inline-edit:focus {
    background: var(--bg);
    border-color: var(--blue);
}

/* --- Filters Bar --- */
.filters-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.filters-bar input[type="search"],
.filters-bar input[type="text"] {
    max-width: 260px;
}

.filters-bar select {
    max-width: 180px;
}

.filter-count {
    font-size: 0.8rem;
    color: var(--text2);
    margin-left: auto;
}

/* --- Modals --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    animation: modalFadeIn 0.2s ease forwards;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-lg);
    max-width: 560px;
    width: 90%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    animation: modalSlideIn 0.3s var(--spring) forwards;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1.1rem;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text2);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    border-radius: 4px;
}
.modal-close:hover {
    color: var(--text);
    background: rgba(255,255,255,0.06);
}

.modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 16px 24px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* --- Side Panel --- */
.side-panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 150;
    display: none;
    opacity: 0;
    transition: opacity var(--transition);
}
.side-panel-overlay.visible {
    display: block;
    opacity: 1;
}

.side-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--side-panel-w);
    max-width: 100vw;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    z-index: 160;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.35s var(--spring);
    box-shadow: var(--shadow-lg);
}
.side-panel.open {
    transform: translateX(0);
}

.side-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.side-panel-title {
    font-size: 1.05rem;
    font-weight: 600;
}

.side-panel-close {
    font-size: 1.5rem;
    color: var(--text2);
    padding: 4px 8px;
    border-radius: 4px;
    line-height: 1;
}
.side-panel-close:hover {
    color: var(--text);
}

.side-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
}

/* --- Toast Notifications --- */
.toast-container {
    position: fixed;
    top: 72px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-btn);
    padding: 12px 20px;
    font-size: 0.85rem;
    color: var(--text);
    box-shadow: var(--shadow);
    pointer-events: auto;
    min-width: 280px;
    max-width: 400px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: toastIn 0.4s var(--spring) forwards;
    cursor: pointer;
}

.toast.toast-out {
    animation: toastOut 0.3s ease-in forwards;
}

.toast-close {
    flex-shrink: 0;
    margin-left: auto;
    font-size: 1.2rem;
    color: var(--text2);
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.15s;
}
.toast-close:hover {
    opacity: 1;
    color: var(--text);
}

.toast-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
}

.toast.toast-success {
    border-left: 3px solid var(--green);
}
.toast.toast-success .toast-icon {
    background: var(--green-bg);
    color: var(--green);
}

.toast.toast-error {
    border-left: 3px solid var(--red);
}
.toast.toast-error .toast-icon {
    background: var(--red-bg);
    color: var(--red);
}

.toast.toast-warning {
    border-left: 3px solid var(--yellow);
}
.toast.toast-warning .toast-icon {
    background: var(--yellow-bg);
    color: var(--yellow);
}

.toast.toast-info {
    border-left: 3px solid var(--blue);
}
.toast.toast-info .toast-icon {
    background: var(--blue-bg);
    color: var(--blue);
}

/* --- Funnel / Pipeline --- */
/* Funnel — compact pipeline */
.funnel-pipeline {
    display: flex;
    align-items: stretch;
    gap: 0;
    margin-bottom: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 12px 8px;
    overflow-x: auto;
}
.funnel-pipeline::-webkit-scrollbar { display: none; }

.funnel-stage {
    flex: 1;
    min-width: 0;
    padding: 0 10px;
    cursor: pointer;
    position: relative;
    transition: background 0.2s;
    border-radius: var(--radius-btn);
}
.funnel-stage:hover {
    background: rgba(255,255,255,0.03);
}

.funnel-stage-top {
    display: flex;
    align-items: baseline;
    gap: 4px;
    margin-bottom: 4px;
}
.funnel-stage-count {
    font-size: 1.1rem;
    font-weight: 800;
    line-height: 1;
}
.funnel-stage-pct {
    font-size: 0.68rem;
    color: var(--text3);
    font-weight: 600;
}

.funnel-stage-bar-bg {
    height: 4px;
    background: rgba(255,255,255,0.06);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 4px;
}
.funnel-stage-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.funnel-stage-label {
    font-size: 0.68rem;
    color: var(--text2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.funnel-stage-arrow {
    position: absolute;
    right: -5px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text3);
    font-size: 1rem;
    opacity: 0.3;
    pointer-events: none;
    z-index: 1;
}

/* Legacy funnel classes (keep for backwards compat) */
.funnel-container { display: flex; gap: 2px; margin-bottom: 24px; border-radius: var(--radius-card); overflow: hidden; }
.funnel-bar { flex: 1; padding: 16px 12px; text-align: center; min-width: 80px; cursor: pointer; }
.funnel-bar-count { font-size: 1.5rem; font-weight: 700; }
.funnel-bar-label { font-size: 0.72rem; margin-top: 4px; opacity: 0.85; }
.funnel-bar-pct { font-size: 0.7rem; opacity: 0.6; margin-top: 2px; }

/* --- Progress Bars --- */
.progress-bar {
    height: 6px;
    background: rgba(255,255,255,0.06);
    border-radius: 3px;
    overflow: hidden;
    width: 100%;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.8s var(--spring);
}

.progress-bar-fill.green { background: var(--green); }
.progress-bar-fill.blue { background: var(--blue); }
.progress-bar-fill.yellow { background: var(--yellow); }
.progress-bar-fill.red { background: var(--red); }

.progress-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.progress-label {
    font-size: 0.8rem;
    color: var(--text2);
    min-width: 100px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.progress-value {
    font-size: 0.8rem;
    font-weight: 600;
    min-width: 50px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* --- Manager Progress (Recovery) — compact cards --- */
.manager-progress-grid {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.mgr-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-btn);
    padding: 10px 14px;
    text-align: center;
    min-width: 80px;
}
.mgr-card-name {
    font-size: 0.72rem;
    color: var(--text2);
    margin-bottom: 2px;
    white-space: nowrap;
}
.mgr-card-stat {
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}
.mgr-card-sep {
    opacity: 0.35;
    font-weight: 400;
}
.mgr-card-pct {
    font-size: 0.7rem;
    font-weight: 600;
}

/* Legacy manager-progress */
.manager-progress {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 20px;
    margin-bottom: 24px;
}
.manager-progress h3 { margin-bottom: 16px; }

/* --- Invoice Timeline --- */
.inv-timeline {
    position: relative;
    padding: 4px 0;
}
.inv-tl-step {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    position: relative;
    padding-bottom: 4px;
}
.inv-tl-dot {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--bg-card);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text3);
    flex-shrink: 0;
    z-index: 1;
}
.inv-tl-step.done .inv-tl-dot {
    color: #fff;
    font-size: 0.75rem;
}
.inv-tl-line {
    position: absolute;
    left: 13px;
    top: 28px;
    width: 2px;
    height: calc(100% - 24px);
    background: var(--border);
}
.inv-tl-step.done .inv-tl-line {
    opacity: 0.6;
}
.inv-tl-content {
    flex: 1;
    padding: 4px 0 12px;
}
.inv-tl-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
}
.inv-tl-step:not(.done) .inv-tl-label {
    color: var(--text3);
}
.inv-tl-date {
    font-size: 0.72rem;
    color: var(--text3);
    margin-top: 1px;
}
.inv-tl-step.done .inv-tl-date {
    color: var(--text2);
}

/* --- Loading / Skeleton --- */
.skeleton {
    background: linear-gradient(90deg, var(--bg-card) 25%, #1e3348 50%, var(--bg-card) 75%);
    background-size: 200px 100%;
    animation: skeletonPulse 1.5s ease-in-out infinite;
    border-radius: var(--radius-card);
}

.skeleton-text {
    height: 14px;
    margin-bottom: 8px;
    width: 80%;
}

.skeleton-title {
    height: 20px;
    width: 40%;
    margin-bottom: 12px;
}

.skeleton-card {
    height: 100px;
    border-radius: var(--radius-card);
}

.skeleton-row {
    height: 44px;
    margin-bottom: 2px;
}

.spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.spinner::after {
    content: '';
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* --- Empty State --- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text2);
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-text {
    font-size: 1rem;
    font-weight: 500;
}

.empty-sub {
    font-size: 0.85rem;
    color: var(--text3);
    margin-top: 4px;
}

/* --- Period Selector --- */
.period-selector {
    display: inline-flex;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-btn);
    overflow: hidden;
}

.period-btn {
    padding: 6px 14px;
    font-size: 0.8rem;
    background: transparent;
    color: var(--text2);
    border: none;
    cursor: pointer;
    font-family: var(--font);
    font-weight: 500;
    transition: all var(--transition);
}
.period-btn:hover:not(.active) {
    background: rgba(67,97,238,0.1);
    color: var(--blue);
}
.period-btn:hover {
    color: var(--text);
}
.period-btn.active {
    background: var(--blue);
    color: #fff;
    box-shadow: 0 2px 8px rgba(67,97,238,0.4);
}

/* --- Bulk Actions --- */
.bulk-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--blue-bg);
    border: 1px solid var(--blue);
    border-radius: var(--radius-btn);
    padding: 8px 16px;
    margin-bottom: 12px;
    font-size: 0.85rem;
    animation: fadeIn 0.2s ease;
}

.bulk-bar .bulk-count {
    font-weight: 600;
    color: var(--blue);
}

/* --- Pagination --- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 16px;
}

.pagination button {
    min-width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text2);
    font-size: 0.8rem;
    font-family: var(--font);
    cursor: pointer;
}
.pagination button:hover {
    background: rgba(255,255,255,0.04);
    color: var(--text);
}
.pagination button.active {
    background: var(--blue);
    color: #fff;
    border-color: var(--blue);
}
.pagination button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.pagination-info {
    font-size: 0.8rem;
    color: var(--text2);
    padding: 0 8px;
}

/* --- Timeline (Side Panel) --- */
.timeline {
    position: relative;
    padding-left: 20px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 4px;
    bottom: 4px;
    width: 2px;
    background: var(--border);
}

.timeline-item {
    position: relative;
    padding-bottom: 20px;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -18px;
    top: 6px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--border);
    border: 2px solid var(--bg-card);
}

.timeline-item.current::before {
    background: var(--blue);
}

.timeline-date {
    font-size: 0.72rem;
    color: var(--text3);
    margin-bottom: 4px;
}

.timeline-content {
    font-size: 0.85rem;
}

.timeline-status {
    font-weight: 600;
}

/* --- Comments --- */
.comment-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 16px;
}

.comment-item {
    background: var(--bg);
    border-radius: var(--radius-btn);
    padding: 12px;
}

.comment-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
}

.comment-author {
    font-size: 0.8rem;
    font-weight: 600;
}

.comment-date {
    font-size: 0.72rem;
    color: var(--text3);
}

.comment-text {
    font-size: 0.85rem;
    color: var(--text2);
    line-height: 1.5;
}

.comment-form {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.comment-form textarea {
    flex: 1;
    min-height: 60px;
}

/* --- Section within panels/cards --- */
.section-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 12px;
    margin-top: 24px;
}

.section-title:first-child {
    margin-top: 0;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(30,51,72,0.3);
    font-size: 0.85rem;
}

.detail-label {
    color: var(--text2);
}

.detail-value {
    font-weight: 500;
    text-align: right;
}

.detail-grid {
    display: flex;
    flex-direction: column;
}

.tab-count {
    font-size: 0.7rem;
    background: var(--bg-card);
    color: var(--text2);
    padding: 1px 7px;
    border-radius: 999px;
    margin-left: 4px;
    font-weight: 600;
    vertical-align: middle;
}
.sub-tab.active .tab-count {
    background: rgba(67,97,238,0.15);
    color: var(--blue);
}

/* --- Tooltip --- */
.has-tooltip {
    position: relative;
    cursor: pointer;
}
.has-tooltip[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 0;
    top: calc(100% + 6px);
    z-index: 50;
    background: #1a2a3a;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.78rem;
    font-weight: 400;
    white-space: pre-wrap;
    max-width: 280px;
    min-width: 140px;
    box-shadow: var(--shadow-lg);
    pointer-events: none;
    line-height: 1.4;
}

.tab-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--blue);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    margin-left: 6px;
    vertical-align: middle;
    line-height: 1;
}
.sub-tab:not(.active) .tab-badge {
    background: #3a4a5c;
    color: var(--text2);
}

/* --- Animations --- */
@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

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

@keyframes scaleIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes toastIn {
    from { transform: translateX(120%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes toastOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(120%); opacity: 0; }
}

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

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

@keyframes barGrow {
    from { transform: scaleX(0); }
    to { transform: scaleX(1); }
}

@keyframes btnShimmer {
    from { transform: translateX(-100%); }
    to { transform: translateX(100%); }
}

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

@keyframes modalSlideIn {
    from { opacity: 0; transform: scale(0.95) translateY(-20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes skeletonPulse {
    0% { background-position: -200px 0; }
    100% { background-position: calc(200px + 100%) 0; }
}

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

/* Stat card value count-up animation on load */
.stat-card-value {
    animation: countUp 0.4s ease-out;
}

/* --- Responsive --- */

/* Collapsed sidebar (tablet) */
@media (max-width: 1024px) {
    .sidebar {
        width: var(--sidebar-collapsed-w);
    }
    .sidebar .nav-text {
        display: none;
    }
    .sidebar .nav-section-title {
        display: none;
    }
    .sidebar .nav-item {
        justify-content: center;
        padding: 10px;
    }
    .content {
        margin-left: var(--sidebar-collapsed-w);
    }
}

/* Mobile */
@media (max-width: 768px) {
    .burger-btn {
        display: flex;
    }

    .sidebar {
        width: var(--sidebar-w);
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar.open + .sidebar-overlay,
    .sidebar-overlay.visible {
        display: block;
    }

    .sidebar .nav-text {
        display: inline;
    }

    .sidebar .nav-item {
        justify-content: flex-start;
        padding: 10px 12px;
    }

    .content {
        margin-left: 0;
        padding: 12px 8px;
    }

    .header-logo-text {
        display: none;
    }

    .rates-widget {
        display: none;
    }

    .user-name {
        display: none;
    }

    /* Page header */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        margin-bottom: 12px;
    }
    .page-header h1 {
        font-size: 1.15rem;
    }
    .page-header-actions {
        width: 100%;
    }
    .page-header-actions .btn {
        flex: 1;
        font-size: 12px;
        padding: 0 12px;
    }

    /* Sub-tabs: horizontal scroll, compact */
    .sub-tabs {
        gap: 0;
        margin-bottom: 12px;
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
    .sub-tabs::-webkit-scrollbar { display: none; }
    .sub-tab {
        padding: 8px 12px;
        font-size: 12px;
        flex-shrink: 0;
    }

    /* Filters: stack vertically */
    .filters-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 6px !important;
    }
    .filters-bar input,
    .filters-bar select {
        max-width: 100% !important;
        width: 100% !important;
        min-width: 0 !important;
        font-size: 13px;
    }

    /* Stat cards */
    .stat-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    .stat-card {
        padding: 12px;
    }
    .stat-card-value {
        font-size: 1.2rem;
    }

    /* Tables */
    .table-wrapper {
        border-radius: 8px;
        margin-bottom: 12px;
    }
    table {
        font-size: 0.78rem;
    }
    thead th {
        padding: 8px 6px;
        font-size: 0.7rem;
    }
    tbody td {
        padding: 8px 6px;
    }
    td.wrap {
        min-width: 140px;
    }

    /* Inline selects in tables */
    .inline-edit, .pipeline-status-select {
        min-width: 100px !important;
        font-size: 11px !important;
        height: 28px !important;
    }

    /* Action buttons in tables */
    .btn-sm {
        font-size: 11px !important;
        padding: 0 8px !important;
        height: 26px !important;
    }

    /* Side panel */
    .side-panel {
        width: 100vw;
    }

    /* Modal */
    .modal-content {
        width: 95%;
        max-width: none;
        max-height: 90vh;
        margin: 5vh auto;
        border-radius: 12px;
    }
    .modal-content .form-group {
        margin-bottom: 10px;
    }

    /* Funnel */
    .funnel-container {
        flex-wrap: wrap;
    }
    .funnel-bar {
        min-width: calc(33% - 2px);
    }
    .funnel-pipeline {
        gap: 0;
        padding: 8px 4px;
        flex-wrap: wrap;
    }
    .funnel-stage {
        padding: 0 4px;
        flex: 1 1 30%;
        min-width: 0;
    }
    .funnel-stage-count {
        font-size: 0.9rem;
    }
    .funnel-stage-label {
        font-size: 0.6rem;
    }

    /* Pagination */
    .page-btn {
        min-width: 28px !important;
        height: 28px !important;
        padding: 0 4px !important;
        font-size: 11px !important;
    }

    /* Detail grid in side panel */
    .detail-grid {
        font-size: 0.82rem;
    }
    .detail-label {
        min-width: 80px;
    }

    /* Toast on mobile */
    .toast-container {
        left: 8px;
        right: 8px;
        top: auto;
        bottom: 12px;
    }
    .toast {
        min-width: auto;
    }
}

@media (max-width: 480px) {
    .stat-cards {
        grid-template-columns: 1fr;
    }
    .content {
        padding: 8px 6px;
    }
    .page-header h1 {
        font-size: 1rem;
    }
    .sub-tab {
        padding: 7px 8px;
        font-size: 11px;
    }
    .tab-badge {
        min-width: 16px;
        height: 16px;
        font-size: 9px;
        padding: 0 4px;
        margin-left: 3px;
    }
    table {
        font-size: 0.72rem;
    }
    thead th {
        padding: 6px 4px;
        font-size: 0.65rem;
    }
    tbody td {
        padding: 6px 4px;
    }
}

/* --- Print --- */
@media print {
    .header, .sidebar, .sidebar-overlay,
    .side-panel, .side-panel-overlay,
    .toast-container, .burger-btn,
    .btn, button, .filters-bar,
    .pagination, .bulk-bar {
        display: none !important;
    }

    body {
        background: #fff;
        color: #000;
        font-size: 11pt;
    }

    .content {
        margin: 0 !important;
        padding: 0 !important;
    }

    .stat-card, .table-wrapper, .alert-card {
        border: 1px solid #ccc;
        background: #fff;
        break-inside: avoid;
    }

    table {
        font-size: 9pt;
    }

    thead th {
        background: #eee !important;
        color: #333;
    }

    .badge {
        border: 1px solid currentColor;
    }

    a {
        color: #000;
        text-decoration: underline;
    }
}

.company-link:hover { color: var(--blue) !important; text-decoration: underline !important; }
