:root {
    --bg: #0a0a0a;
    --bg-card: #141414;
    --bg-input: #1a1a1a;
    --border: #1e1e1e;
    --text: #e0e0e0;
    --text-muted: #888;
    --accent: #4a9eff;
    --accent-hover: #3a8eef;
    --danger: #e55;
    --danger-hover: #d44;
    --success: #4caf50;
    --error: #e55;
    --radius: 8px;
}

/* Cards */
.card, .auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
}

.auth-card {
    max-width: 400px;
    margin: 4rem auto 0;
}

h1 {
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
}

h2 {
    font-size: 1.1rem;
    font-weight: 500;
    margin: 1.5rem 0 1rem;
    color: var(--text-muted);
}

section + section {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.4rem;
    color: var(--text-muted);
}

.hint {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 0.8rem;
}

select,
input[type="text"],
input[type="password"],
input[type="number"],
textarea {
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

select:focus, input:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
}

input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.form-row {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.form-row .form-group {
    flex: 1;
    min-width: 120px;
}

.form-group-btn {
    padding-bottom: 1rem;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: var(--danger-hover);
}

.btn-sm {
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
}

/* Flash messages */
.flash-messages {
    margin-bottom: 1.5rem;
}

.flash {
    padding: 0.8rem 1rem;
    border-radius: 6px;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    word-break: break-all;
}

.flash-success {
    background: rgba(76, 175, 80, 0.15);
    border: 1px solid rgba(76, 175, 80, 0.3);
    color: var(--success);
}

.flash-error {
    background: rgba(238, 85, 85, 0.15);
    border: 1px solid rgba(238, 85, 85, 0.3);
    color: var(--error);
}

.error-text {
    color: var(--error);
    margin-bottom: 1rem;
}

/* Tables */
.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

th, td {
    padding: 0.6rem 0.8rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
}

.token-cell {
    font-family: monospace;
    font-size: 0.8rem;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-active {
    background: rgba(76, 175, 80, 0.2);
    color: var(--success);
}

.badge-revoked {
    background: rgba(238, 85, 85, 0.2);
    color: var(--error);
}

.badge-used {
    background: rgba(136, 136, 136, 0.2);
    color: var(--text-muted);
}

.badge-family {
    background: rgba(255, 183, 77, 0.2);
    color: #ffb74d;
}

.badge-admin {
    background: rgba(74, 158, 255, 0.2);
    color: var(--accent);
}

.badge-general {
    background: rgba(136, 136, 136, 0.2);
    color: var(--text-muted);
}

.badge-premium {
    background: rgba(139, 92, 246, 0.2);
    color: #a78bfa;
}

/* Profile meta */
.profile-meta {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--text-muted);
}

.profile-meta p {
    margin-bottom: 0.3rem;
}

.inline {
    display: inline;
}

.status-form select {
    padding: 0.3rem 0.5rem;
    font-size: 0.8rem;
    width: auto;
}

/* Section header */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.section-header h2 {
    margin: 0;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%;
    max-width: 400px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.1rem;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--text);
}

/* Admin layout */
.admin-layout {
    display: flex;
    gap: 1.5rem;
    min-height: calc(100vh - 120px);
}

.admin-sidebar {
    width: 200px;
    flex-shrink: 0;
}

.admin-tree {
    position: sticky;
    top: 1rem;
}

.tree-parent {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.02em;
    margin-top: 0.75rem;
}

.tree-parent:first-child {
    margin-top: 0;
}

.tree-children {
    display: flex;
    flex-direction: column;
}

.tree-children a {
    display: block;
    padding: 0.45rem 0.75rem 0.45rem 2.25rem;
    border-radius: 6px;
    font-size: 0.83rem;
    color: var(--text-muted);
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
    position: relative;
}

.tree-children a::before {
    content: '';
    position: absolute;
    left: 1.2rem;
    top: 50%;
    width: 0.5rem;
    border-top: 1px solid var(--border);
}

.tree-children a:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
}

.tree-children a.active {
    background: rgba(74, 158, 255, 0.1);
    color: var(--accent);
}

.form-narrow {
    max-width: 400px;
}

/* Admin sub-navigation */
.admin-subnav {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
}

.admin-subnav-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
}

.admin-subnav-icon {
    display: flex;
    align-items: center;
    color: var(--text-muted);
    text-decoration: none;
}

.admin-subnav-icon:first-child {
    margin-right: auto;
}

.admin-subnav-icon svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.admin-subnav-icon:hover {
    color: var(--text);
}

.admin-subnav-link {
    font-size: 0.9rem;
    color: var(--text-muted);
    text-decoration: none;
}

.admin-subnav-link:hover {
    color: var(--text);
}

.admin-subnav-link.active {
    font-weight: 600;
    color: var(--text);
}

.admin-subnav-user {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.admin-main {
    flex: 1;
    min-width: 0;
}

.admin-layout .container,
.admin-layout ~ .container {
    max-width: none;
}

/* Analytics */
.period-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 1rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.hourly-chart {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.hourly-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.hourly-label {
    width: 1.8rem;
    text-align: right;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: monospace;
}

.bar-bg {
    flex: 1;
    height: 1rem;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
}

.bar {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    min-width: 0;
    transition: width 0.3s;
}

.hourly-count {
    width: 2.5rem;
    text-align: right;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: monospace;
}

.log-table {
    font-size: 0.78rem;
}

.log-table td, .log-table th {
    padding: 0.4rem 0.6rem;
}

.ua-cell {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.nowrap {
    white-space: nowrap;
}

.text-muted {
    color: var(--text-muted);
}

/* Interactive: Like button */
.post-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-top: 0.4rem;
}

.btn-like {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0.15rem 0.5rem;
    transition: color 0.2s, border-color 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.btn-like:hover {
    color: #e55;
    border-color: #e55;
}

.btn-like.liked {
    color: #e55;
    border-color: #e55;
}

.like-count {
    font-size: 0.8rem;
}

/* Interactive: Hide button (admin) */
.btn-hide {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
    transition: color 0.2s, border-color 0.2s;
}

.btn-hide:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.btn-hide.is-hidden {
    color: var(--danger);
    border-color: var(--danger);
}

.admin-hidden {
    opacity: 0.4;
}

/* Interactive: Category filter */
.category-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.75rem 0;
}

.filter-btn {
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.25rem 0.6rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.filter-btn.on {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.filter-btn.off {
    background: var(--bg-input);
    color: var(--text-muted);
}

.filter-btn:hover {
    opacity: 0.85;
}

/* Responsive */
@media (max-width: 768px) {
    .admin-layout {
        flex-direction: column;
        gap: 1rem;
    }
    .admin-sidebar {
        width: 100%;
    }
    .admin-tree {
        position: static;
        display: flex;
        gap: 0.5rem;
    }
    .tree-section {
        display: none;
    }
}

@media (max-width: 600px) {
    .container { padding: 1rem; }
    .card, .auth-card { padding: 1.5rem; }
    .auth-card { margin-top: 2rem; }
    .form-row { flex-direction: column; }
}

/* ===== Budget ===== */

/* App shell */
.budget-app {
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.budget-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 100;
}

.budget-header-icon {
    color: var(--text-muted);
    text-decoration: none;
    display: flex;
    align-items: center;
    padding: 0.3rem;
    transition: color 0.15s;
}

.budget-header-icon:hover {
    color: var(--text);
}

.budget-header-spacer {
    width: 28px;
}

.budget-header-title {
    font-size: 1rem;
    font-weight: 600;
}

.budget-main {
    flex: 1;
    padding: 1rem;
    padding-bottom: 5rem;
}

.budget-tabbar {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0.4rem 0 0.6rem;
    border-top: 1px solid var(--border);
    background: var(--bg);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

.budget-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.68rem;
    padding: 0.2rem 0.8rem;
    transition: color 0.15s;
}

.budget-tab:hover {
    color: var(--text);
}

.budget-tab.active {
    color: var(--accent);
}

.budget-container {
    max-width: 480px;
    margin: 0 auto;
}

.budget-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.budget-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.budget-toggle {
    cursor: pointer;
    user-select: none;
}

.budget-card-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toggle-arrow {
    font-size: 0.7rem;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.budget-card-body {
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.2s ease;
    max-height: 1000px;
    opacity: 1;
}

.budget-card-body.collapsed {
    max-height: 0;
    opacity: 0;
}

.budget-card-body.collapsed + .budget-card-header,
.budget-toggle:has(+ .collapsed) {
    margin-bottom: 0;
}

/* Remove bottom margin from header when body is collapsed */
.budget-card:has(.collapsed) .budget-card-header {
    margin-bottom: 0;
}

.budget-card-title {
    font-size: 1rem;
    font-weight: 600;
}

.budget-card-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.budget-card-link {
    font-size: 0.8rem;
    color: var(--accent);
    text-decoration: none;
}

.budget-card-link:hover {
    text-decoration: underline;
}

/* Summary (donut + numbers) */
.summary-body {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.donut-area {
    width: 120px;
    flex-shrink: 0;
}

.donut-chart {
    width: 100%;
    height: auto;
}

.summary-numbers {
    flex: 1;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.3rem 0;
}

.summary-row-total {
    border-top: 1px solid var(--border);
    margin-top: 0.3rem;
    padding-top: 0.5rem;
}

.summary-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.summary-value {
    font-size: 1.2rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.summary-value.income {
    color: var(--text);
}

.summary-value.expense {
    color: var(--danger);
}

/* Category legend */
.category-legend {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.3rem 1rem;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.78rem;
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.legend-name {
    color: var(--text-muted);
    flex: 1;
}

.legend-amount {
    font-variant-numeric: tabular-nums;
    color: var(--text);
}

/* Budget progress */
.budget-progress-area {
    padding: 0.25rem 0;
}

.budget-progress-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.5rem;
}

.budget-progress-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.budget-progress-remaining {
    font-size: 1.1rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.budget-progress-remaining.expense {
    color: var(--danger);
}

.budget-bar-bg {
    width: 100%;
    height: 8px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
}

.budget-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
    transition: width 0.3s;
}

.budget-bar-warn {
    background: #ffb74d;
}

.budget-bar-danger {
    background: var(--danger);
}

.budget-warning {
    font-size: 0.78rem;
    color: var(--danger);
    margin-top: 0.4rem;
    text-align: right;
}

/* Transaction list */
.transaction-list {
    display: flex;
    flex-direction: column;
}

.transaction-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border);
}

.transaction-row:last-child {
    border-bottom: none;
}

.transaction-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.transaction-date {
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
    width: 3rem;
    flex-shrink: 0;
}

.transaction-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.transaction-desc {
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.transaction-cat {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.transaction-amount {
    font-size: 0.9rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    margin-left: 1rem;
}

.transaction-amount.income {
    color: var(--text);
}

.transaction-amount.expense {
    color: var(--danger);
}

/* Import form */
.import-form {
    max-width: 400px;
}

.file-input {
    width: 100%;
    padding: 0.6rem;
    background: var(--bg-input);
    border: 1px dashed var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
}

.file-input:hover {
    border-color: var(--accent);
}

/* Accounts */
.account-balance {
    text-align: right;
}

.account-balance-value {
    font-size: 1.3rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.account-balance-total {
    color: var(--accent);
}

.account-updated {
    text-align: right;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
}
