:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface2: #222633;
    --border: #2d3140;
    --text: #e4e6eb;
    --text2: #9ca3af;
    --accent: #6366f1;
    --accent2: #818cf8;
    --green: #22c55e;
    --red: #ef4444;
    --yellow: #eab308;
    --header-bg: #15171f;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

/* --- Layout --- */
.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}
.app-header h1 { font-size: 18px; font-weight: 600; }
.app-header nav { display: flex; gap: 16px; align-items: center; }
.app-header nav a {
    color: var(--text2);
    text-decoration: none;
    font-size: 14px;
    transition: color .15s;
}
.app-header nav a:hover, .app-header nav a.active { color: var(--accent2); }
.user-badge {
    background: var(--surface2);
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 13px;
    color: var(--text2);
}

.container { max-width: 100%; padding: 16px 24px; }

/* --- Login page --- */
.login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    gap: 24px;
}
.login-container h1 { font-size: 28px; font-weight: 700; }
.login-container p { color: var(--text2); }

/* --- Dashboard table --- */
.group-section {
    margin-bottom: 24px;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.group-header {
    background: var(--surface);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
}
.group-header:hover { background: var(--surface2); }
.group-header h3 { font-size: 15px; font-weight: 600; }
.group-header .badge {
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
}
.group-header .chevron {
    transition: transform .2s;
    color: var(--text2);
    font-size: 18px;
}
.group-section.open .group-header .chevron { transform: rotate(180deg); }
.group-body { display: none; overflow-x: auto; }
.group-section.open .group-body { display: block; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    white-space: nowrap;
}
.data-table th, .data-table td {
    padding: 4px 10px;
    border: 1px solid var(--border);
    text-align: right;
}
.data-table th {
    background: var(--header-bg);
    position: sticky;
    top: 0;
    font-weight: 500;
    color: var(--text2);
    font-size: 12px;
    z-index: 2;
}
.data-table td:first-child,
.data-table th:first-child {
    text-align: left;
    position: sticky;
    left: 0;
    background: var(--surface);
    z-index: 1;
    min-width: 180px;
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.data-table th:first-child {
    background: var(--header-bg);
    z-index: 3;
}
.data-table td.total-col {
    background: var(--surface2);
    font-weight: 600;
}
.data-table tr:hover td {
    background: var(--surface2);
}
.data-table tr:hover td:first-child {
    background: #262a38;
}
.data-table tr.total-row td {
    background: var(--surface);
    font-weight: 600;
    border-top: 2px solid var(--border);
}
.data-table tr.total-row td:first-child {
    background: var(--surface);
}
.data-table .zero { color: var(--border); }
.data-table .usd::before { content: '$'; }

/* --- Conversion rows --- */
.conversion-row {
    margin: -1px 0;
    border-left: 3px solid var(--accent);
}
.conversion-table { background: var(--surface); }
.conversion-table .cr-row td {
    padding: 6px 10px;
    font-size: 13px;
    font-weight: 600;
    color: var(--green);
    background: rgba(34, 197, 94, 0.05);
    border: 1px solid var(--border);
    text-align: right;
}
.conversion-table .cr-row td:first-child {
    text-align: left;
    position: sticky;
    left: 0;
    background: rgba(34, 197, 94, 0.08);
    z-index: 1;
    min-width: 180px;
}
.conversion-table .cr-row td .zero { color: var(--border); }

/* --- Groups management --- */
.groups-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 20px;
    min-height: calc(100vh - 80px);
}
.groups-list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
}
.groups-list h3 {
    font-size: 14px;
    color: var(--text2);
    margin-bottom: 8px;
    padding: 0 4px;
}
.group-item {
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.group-item:hover { background: var(--surface2); }
.group-item.selected { background: var(--accent); color: #fff; }
.group-item .count { font-size: 12px; color: var(--text2); }
.group-item.selected .count { color: rgba(255,255,255,.7); }

.group-detail {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
}
.group-detail h2 { font-size: 18px; margin-bottom: 16px; }
.group-detail .field { margin-bottom: 12px; }
.group-detail label {
    display: block;
    font-size: 12px;
    color: var(--text2);
    margin-bottom: 4px;
}

/* --- Form elements --- */
input, select {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 14px;
    width: 100%;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--accent);
}
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    transition: background .15s;
}
.btn:hover { background: var(--border); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: rgba(239,68,68,.15); }
.btn-sm { padding: 3px 8px; font-size: 12px; }

.patterns-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 12px;
}
.patterns-table th, .patterns-table td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    font-size: 13px;
}
.patterns-table th {
    color: var(--text2);
    font-weight: 500;
    font-size: 12px;
}
.patterns-table input {
    width: 100%;
    background: transparent;
    border: 1px solid transparent;
    padding: 2px 6px;
}
.patterns-table input:focus {
    background: var(--bg);
    border-color: var(--accent);
}
.patterns-table td:last-child { width: 40px; text-align: center; }

/* --- Loading --- */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px;
    color: var(--text2);
}
.spinner {
    width: 24px; height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .6s linear infinite;
    margin-right: 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Responsive --- */
@media (max-width: 768px) {
    .groups-layout { grid-template-columns: 1fr; }
    .container { padding: 12px; }
    .app-header { padding: 10px 12px; }
}
