/* ==========================================================
   GIAO DIỆN HIỆN ĐẠI - HỆ THỐNG QUẢN LÝ QUỸ LỚP 12 LÝ
   Phong cách: Modern Glassmorphism & High-end Fintech Dashboard
   ========================================================== */

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #e0e7ff;
    --primary-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    
    --success: #10b981;
    --success-bg: #d1fae5;
    --success-gradient: linear-gradient(135deg, #10b981 0%, #059669 100%);
    
    --danger: #ef4444;
    --danger-bg: #fee2e2;
    --danger-gradient: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    
    --warning: #f59e0b;
    --warning-bg: #fef3c7;
    --warning-gradient: linear-gradient(135deg, #f59e0b 0%, #f97316 100%);
    
    --info: #0ea5e9;
    --info-bg: #e0f2fe;
    --info-gradient: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);

    --bg-main: #f8fafc;
    --card-bg: #ffffff;
    --card-border: #e2e8f0;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-full: 9999px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Container */
.app-container {
    max-width: min(1560px, calc(100vw - 48px));
    margin: 0 auto;
    padding: 20px 0 80px;
}
.top-sticky-panel { position: sticky; top: 0; z-index: 100; background: rgba(248,250,252,.96); backdrop-filter: blur(14px); padding-bottom: 12px; box-shadow: 0 8px 18px rgba(15,23,42,.08); }

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 24px;
    position: sticky;
    top: 12px;
    z-index: 100;
}

.brand-section {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-icon {
    width: 58px;
    height: 58px;
    background: #fff;
    color: #b7791f;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    font-size: 22px;
    border: 1px solid #e5b85c;
    box-shadow: 0 4px 12px rgba(180, 130, 35, 0.18);
}

.brand-title {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-icon-btn {
    width: 32px;
    height: 32px;
    display: none;
    align-items: center;
    justify-content: center;
    border: 1px solid #dbe4f0;
    border-radius: 8px;
    background: #fff;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}

.header-icon-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.header-icon-btn.is-save {
    color: #fff;
    background: var(--primary);
    border-color: var(--primary);
}

.header-title-edit {
    display: flex;
    align-items: center;
    gap: 8px;
    width: min(620px, 62vw);
}

.header-title-edit .header-icon-btn {
    display: inline-flex;
    flex: 0 0 auto;
}

.header-title-edit input {
    flex: 1;
    min-width: 220px;
    height: 38px;
    border: 1px solid #cbd5e1;
    border-radius: 9px;
    padding: 8px 11px;
    color: var(--text-main);
    font: inherit;
    font-size: 1rem;
    outline: none;
}

.header-title-edit input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,.14);
}

.brand-badge {
    background: var(--primary-light);
    color: var(--primary);
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-weight: 700;
}

.brand-subtitle {
    font-size: 0.82rem;
    color: var(--text-muted);
}

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

/* Admin Status Badge */
.admin-badge-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--card-border);
    background: #fff;
    color: var(--text-main);
    transition: var(--transition);
}

.admin-badge-btn:hover {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
}

.admin-badge-btn.logged-in {
    background: #ecfdf5;
    border-color: #a7f3d0;
    color: #065f46;
}

.header-settings-btn {
    display: none;
}

.admin-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #94a3b8;
}

.admin-badge-btn.logged-in .admin-dot {
    background: #10b981;
    box-shadow: 0 0 8px #10b981;
}

/* ==========================================================
   METRICS DASHBOARD CARDS
   ========================================================== */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 24px;
}

.metric-card {
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    padding: 20px;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.metric-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.metric-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
}

.metric-card.balance::before { background: var(--info-gradient); }
.metric-card.collected::before { background: var(--success-gradient); }
.metric-card.spent::before { background: var(--danger-gradient); }
.metric-card.rate::before { background: var(--primary-gradient); }

.metric-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.metric-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.metric-icon-wrap {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
}

.metric-card.balance .metric-icon-wrap { background: var(--info-bg); color: var(--info); }
.metric-card.collected .metric-icon-wrap { background: var(--success-bg); color: var(--success); }
.metric-card.spent .metric-icon-wrap { background: var(--danger-bg); color: var(--danger); }
.metric-card.rate .metric-icon-wrap { background: var(--primary-light); color: var(--primary); }

.metric-value {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.02em;
    margin-bottom: 4px;
}

.metric-value.emerald { color: #059669; }
.metric-value.rose { color: #e11d48; }
.metric-value.sky { color: #0284c7; }

.metric-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Progress bar inside rate card */
.progress-bar-bg {
    width: 100%;
    height: 7px;
    background: #e2e8f0;
    border-radius: var(--radius-full);
    overflow: hidden;
    margin-top: 10px;
}

.progress-bar-fill {
    height: 100%;
    background: var(--primary-gradient);
    border-radius: var(--radius-full);
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================
   NAVIGATION TABS
   ========================================================== */
.nav-tabs-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    padding: 6px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap;
    gap: 10px;
}

.nav-tabs {
    display: flex;
    gap: 6px;
}

.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.92rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.tab-btn:hover {
    color: var(--text-main);
    background: #f1f5f9;
}

.tab-btn.active {
    background: var(--primary-gradient);
    color: #fff;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

.tab-count {
    background: rgba(0, 0, 0, 0.08);
    color: inherit;
    padding: 2px 7px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
}

.tab-btn.active .tab-count {
    background: rgba(255, 255, 255, 0.25);
}

.nav-tab-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-right: 6px;
}

/* ==========================================================
   SEARCH & FILTERS TOOLBAR
   ========================================================== */
.toolbar-section {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-box {
    position: relative;
    flex: 1;
    min-width: 260px;
}

.search-box input {
    width: 100%;
    padding: 12px 16px 12px 42px;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    font-size: 0.92rem;
    font-family: inherit;
    background: #fff;
    color: var(--text-main);
    outline: none;
    transition: var(--transition);
}

.search-box input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
    font-size: 1.05rem;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 8px 14px;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-full);
    background: #fff;
    color: var(--text-muted);
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.filter-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.filter-btn.active {
    background: var(--text-main);
    border-color: var(--text-main);
    color: #fff;
}

/* ==========================================================
   MEMBERS GRID & CARDS
   ========================================================== */
.members-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

.member-card {
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    cursor: pointer;
    position: relative;
    min-width: 0;
}
.brand-icon img { width: 100%; height: 100%; object-fit: contain; border-radius: inherit; }
#btn-top-add-expense { display: none !important; }

.member-card:hover {
    border-color: #cbd5e1;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.member-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1;
}

.member-avatar {
    width: 52px;
    height: 52px;
    aspect-ratio: 1 / 1;
    display: block;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #e2e8f0;
    background: #f1f5f9;
    flex-shrink: 0;
}

.member-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.member-name {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.3;
    overflow-wrap: anywhere;
    white-space: nowrap;
    overflow: visible;
    text-overflow: clip;
    font-size: .86rem;
}

.member-role {
    font-size: 0.76rem;
    color: var(--text-muted);
    margin-bottom: 3px;
}

.member-paid {
    font-size: 0.82rem;
    font-weight: 700;
    color: #059669;
}

.member-paid.zero {
    color: var(--text-light);
    font-weight: 500;
}

.member-birthdate { font-size: .74rem; color: var(--text-muted); margin: 3px 0; }
.member-profile-edit-form {
    display: none;
    margin: -8px 0 20px;
    padding: 14px;
    border: 1px solid #dbe4f0;
    border-radius: var(--radius-md);
    background: #fff;
}
.member-profile-edit-form.active { display: block; }
.member-profile-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.member-profile-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 4px;
}
.avatar-editor {
    display: grid;
    grid-template-columns: 72px 1fr;
    gap: 12px;
    align-items: start;
}
.avatar-editor-preview {
    width: 72px;
    height: 72px;
    aspect-ratio: 1 / 1;
    display: block;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #cbd5e1;
    background: #f8fafc;
}
.avatar-editor-main { min-width: 0; }
.avatar-choice-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}
.avatar-choice {
    width: 46px;
    height: 46px;
    border: 2px solid transparent;
    border-radius: 50%;
    padding: 2px;
    background: #fff;
    cursor: pointer;
    transition: var(--transition);
}
.avatar-choice img {
    width: 100%;
    height: 100%;
    display: block;
    aspect-ratio: 1 / 1;
    border-radius: 50%;
    object-fit: cover;
}
.avatar-choice:hover,
.avatar-choice.active {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}
.avatar-upload-btn { width: fit-content; }
#edit-member-avatar-file { display: none; }
.avatar-cropper {
    display: none;
    margin-top: 12px;
    padding: 12px;
    border: 1px solid #dbe4f0;
    border-radius: 10px;
    background: #f8fafc;
}
.avatar-cropper.active { display: grid; gap: 10px; }
.avatar-crop-frame {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    overflow: hidden;
    position: relative;
    background: #e2e8f0;
    border: 2px solid #cbd5e1;
    cursor: grab;
    touch-action: none;
    user-select: none;
}
.avatar-crop-frame:active { cursor: grabbing; }
.avatar-crop-frame img {
    position: absolute;
    left: 0;
    top: 0;
    max-width: none;
    transform-origin: top left;
    user-select: none;
    pointer-events: none;
}
.avatar-crop-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}
.avatar-crop-actions span {
    color: var(--text-muted);
    font-size: .78rem;
    font-weight: 700;
}
.admin-cycle-toolbar { margin: 14px 0 16px; padding: 14px; border: 1px solid #dbe4f0; border-radius: 10px; background: #f8fafc; }
.admin-cycle-controls { position:relative; }
.admin-cycle-trigger { width:100%; min-height:44px; display:flex; align-items:center; justify-content:space-between; gap:12px; border:1px solid #cbd5e1; border-radius:10px; background:#fff; padding:9px 14px; color:var(--text-main); text-align:left; cursor:pointer; transition:var(--transition); }
.admin-cycle-trigger:hover, .admin-cycle-trigger:focus { border-color:var(--primary); box-shadow:0 0 0 3px rgba(79,70,229,.12); outline:none; }
.admin-cycle-trigger span { display:block; min-width:0; }
.admin-cycle-trigger strong { display:block; font-size:.92rem; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.admin-cycle-trigger i { color:var(--text-muted); flex:0 0 auto; }
.admin-cycle-menu { display:none; position:absolute; left:0; right:0; top:calc(100% + 6px); z-index:30; max-height:260px; overflow:auto; padding:6px; border:1px solid #dbe4f0; border-radius:10px; background:#fff; box-shadow:var(--shadow-lg); }
.admin-cycle-menu.active { display:grid; gap:4px; }
.admin-cycle-menu button { display:flex; align-items:center; justify-content:space-between; gap:12px; width:100%; border:0; border-radius:8px; background:transparent; padding:10px 12px; color:var(--text-main); text-align:left; cursor:pointer; }
.admin-cycle-menu button:hover, .admin-cycle-menu button.active { background:#eef2ff; }
.admin-cycle-menu span { display:block; min-width:0; }
.admin-cycle-menu strong { display:block; font-size:.88rem; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.cycle-list { display: grid; gap: 8px; margin-bottom: 16px; }
.cycle-settings-actions { display:flex; gap:10px; flex-wrap:wrap; padding-top:4px; }
.cycle-row { display:grid; grid-template-columns:minmax(0,1fr) auto; align-items:start; gap:12px; padding:14px 16px; border:1px solid var(--card-border); border-radius:8px; background:#f8fafc; cursor:pointer; transition:border-color .18s ease, background .18s ease, box-shadow .18s ease; }
.cycle-row:hover { border-color:#c7d2fe; background:#fff; box-shadow:0 8px 22px rgba(15,23,42,.06); }
.cycle-main { display:flex; flex-direction:column; gap:5px; min-width:0; }
.cycle-row strong { display:flex; align-items:center; gap:6px; flex-wrap:wrap; font-size:.9rem; line-height:1.3; color:var(--text-main); }
.cycle-edit-name-btn { width:26px; height:26px; display:inline-flex; align-items:center; justify-content:center; border:1px solid #dbe4f0; border-radius:7px; background:#fff; color:var(--primary); cursor:pointer; transition:var(--transition); }
.cycle-edit-name-btn:hover { background:var(--primary-light); border-color:#c7d2fe; }
.cycle-row span:not(.cycle-status) { color:var(--text-muted); font-size:.78rem; line-height:1.45; }
.cycle-status { padding:4px 9px; border-radius:999px; font-size:.72rem; font-weight:700; white-space:nowrap; }
.cycle-status.open { background:#dcfce7; color:#166534; }
.cycle-status.locked { background:#e2e8f0; color:#475569; }
.cycle-status.planned { background:#fef3c7; color:#92400e; }
.cycle-row.is-active-cycle { border-color:#818cf8; background:#eef2ff; box-shadow:0 0 0 2px rgba(129,140,248,.14); }
.cycle-row.is-editing { background:#fff; border-color:#6366f1; cursor:default; }
.active-cycle-label { font-style:normal; font-size:.64rem; color:#4338ca; background:#c7d2fe; padding:3px 6px; border-radius:999px; vertical-align:middle; }
.cycle-side { display:flex; flex-direction:column; align-items:flex-end; gap:8px; }
.cycle-actions { display:flex; flex-direction:row; align-items:center; justify-content:flex-end; gap:6px; }
.cycle-actions .btn-sm { min-height:32px; padding:7px 9px; border-radius:8px; }
.btn-subtle-danger { background:#fff; border:1px solid #fecaca; color:#b91c1c; box-shadow:none; }
.btn-subtle-danger:hover { background:#fef2f2; border-color:#fca5a5; color:#991b1b; transform:none; box-shadow:none; }
.cycle-edit-form { grid-column:1/-1; display:grid; grid-template-columns:minmax(220px,1.2fr) minmax(160px,.8fr) auto; align-items:end; gap:8px 12px; margin-top:4px; padding-top:12px; border-top:1px solid #e2e8f0; }
.cycle-edit-form label { color:var(--text-muted); font-size:.74rem; font-weight:700; }
.cycle-edit-form label:nth-of-type(1) { grid-column:1; grid-row:1; }
.cycle-edit-form input:nth-of-type(1) { grid-column:1; grid-row:2; }
.cycle-edit-form label:nth-of-type(2) { grid-column:2; grid-row:1; }
.cycle-edit-form input:nth-of-type(2) { grid-column:2; grid-row:2; }
.cycle-edit-form input { width:100%; min-height:40px; border:1px solid #cbd5e1; border-radius:8px; padding:8px 11px; color:var(--text-main); font-size:.95rem; font-weight:700; outline:none; }
.cycle-edit-form input:focus { border-color:#6366f1; box-shadow:0 0 0 3px rgba(99,102,241,.16); }
.cycle-edit-actions { grid-column:3; grid-row:2; display:flex; align-items:center; justify-content:flex-end; gap:8px; }
.cycle-edit-actions .btn-sm { min-height:40px; padding:9px 12px; border-radius:8px; white-space:nowrap; }
.cycle-members { display:grid; grid-template-columns:repeat(2,minmax(220px,1fr)); gap:5px 14px; margin-top:10px; max-width:760px; }
.cycle-member-chip { display:flex; justify-content:space-between; gap:10px; padding:5px 8px; background:#fff; border:1px solid #e2e8f0; border-radius:6px; font-size:.75rem; }
.cycle-member-chip small { color:var(--text-muted); white-space:nowrap; }
.cycles-tab-card { background:#fff; border:1px solid var(--card-border); border-radius:var(--radius-lg); padding:22px; box-shadow:var(--shadow-sm); }
.cycles-tab-title { display:flex; justify-content:space-between; align-items:center; margin-bottom:18px; }
.cycles-tab-title h2 { margin:0 0 4px; font-size:1.2rem; }
.cycles-tab-title p { margin:0; color:var(--text-muted); font-size:.85rem; }
.cycles-tab-title > i { color:var(--primary); font-size:1.5rem; }
.cycle-summary-list { display:grid; gap:10px; }
.cycle-summary-row { display:grid; grid-template-columns:minmax(260px,1.6fr) 1fr 1fr 1fr auto; gap:16px; align-items:center; padding:15px 16px; border:1px solid var(--card-border); border-radius:var(--radius-md); background:#f8fafc; }
.cycle-summary-row.active { border-color:#818cf8; background:#eef2ff; }
.cycle-summary-row > div:not(.cycle-summary-name) { display:flex; flex-direction:column; gap:3px; }
.cycle-summary-row small { color:var(--text-muted); font-size:.75rem; }
.cycle-summary-name { display:flex; flex-direction:column; gap:4px; }
.cycle-summary-name span { color:#4338ca; font-size:.72rem; font-weight:700; }
.overview-cycles-card { margin-top:20px; padding:18px 20px; background:#fff; border:1px solid var(--card-border); border-radius:var(--radius-lg); box-shadow:var(--shadow-sm); }
.overview-cycles-title { display:flex; align-items:baseline; justify-content:space-between; gap:14px; margin-bottom:12px; }
.overview-cycles-title h2 { margin:0; font-size:1rem; color:var(--text-main); }
.overview-cycles-title span { color:var(--text-muted); font-size:.78rem; }
@media(max-width:1100px){.settings-grid{grid-template-columns:1fr;}.cycle-manager-card{min-height:auto;}.app-container{max-width:min(1000px, calc(100vw - 32px));}}
@media(max-width:900px){.cycle-summary-row{grid-template-columns:1fr 1fr;}.cycle-summary-name{grid-column:1/-1;}}
@media(max-width:640px){.cycle-row{grid-template-columns:1fr;}.cycle-side{align-items:flex-start; flex-direction:row; justify-content:space-between; width:100%;}.cycle-edit-form{grid-template-columns:1fr;}.cycle-edit-form label,.cycle-edit-form input,.cycle-edit-actions{grid-column:1 !important; grid-row:auto !important;}.cycle-edit-actions{justify-content:stretch;}.cycle-edit-actions .btn{flex:1;}}
@media(max-width:640px){.brand-title{align-items:flex-start; flex-wrap:wrap;}.header-title-edit{width:100%; flex-wrap:wrap;}.header-title-edit input{min-width:100%;}.header-title-edit .header-icon-btn{display:inline-flex;}}
.metric-cycle-name { font-size:.72rem; color:var(--primary); font-weight:700; margin-top:4px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.metric-card.cycle-total::before { background: var(--warning-gradient); }
.metric-card.cycle-total .metric-icon-wrap { background:var(--warning-bg); color:#b45309; }
#stat-paid-percentage, #stat-cycle-name { display:none !important; }
.metric-card.rate { display:none; }
.metric-card.cycle-total .metric-desc { display:none; }
.overview-cycles-card { display:none; }
.top-cycle-list { display:grid; gap:7px; margin-top:2px; }
.metric-card.cycle-total { min-height:174px; padding:18px; overflow:hidden; }
.metric-card.cycle-total .metric-header { margin-bottom:8px; }
.metric-card.cycle-total .metric-title { color:#92400e; }
.top-cycle-item { display:flex; flex-direction:column; gap:5px; padding:10px 12px; border:1px solid #fde68a; border-radius:12px; background:#fffbeb; min-width:0; box-shadow: inset 0 0 0 1px rgba(255,255,255,.55); overflow:hidden; }
.top-cycle-item:last-child { border-bottom:0; }
.top-cycle-item strong { font-size:.76rem; color:#78350f; white-space:normal; line-height:1.25; }
.top-cycle-item span { font-size:.7rem; color:#92400e; font-weight:600; }
.top-cycle-head, .top-cycle-progress-label { display:flex; justify-content:space-between; align-items:center; gap:8px; }
.top-cycle-progress-label { margin-top:5px; color:#92400e; font-size:.68rem; }
.top-cycle-progress-label b { font-size:.68rem; }
.top-cycle-progress { height:6px; margin-top:5px; background:#fde68a; border-radius:99px; overflow:hidden; }
.top-cycle-progress i { display:block; height:100%; background:#f59e0b; border-radius:inherit; transition:width .3s ease; }
.cycle-view-label { font-size:.82rem; font-weight:700; color:var(--text-muted); white-space:nowrap; }
.cycle-view-select { padding:9px 12px; border:1px solid var(--card-border); border-radius:var(--radius-sm); background:#fff; color:var(--text-main); font:inherit; font-size:.84rem; max-width:260px; }

.member-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
    width: 154px;
    flex-shrink: 0;
    align-items: stretch;
}

.member-cycle-label {
    color: var(--text-muted);
    font-size: .68rem;
    font-weight: 700;
    line-height: 1.25;
    text-align: right;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.member-cycle-paid {
    color: var(--text-main);
    font-size: .74rem;
    font-weight: 800;
    text-align: right;
}

/* Status Badges */
.status-pill {
    font-size: 0.74rem;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    justify-content: center;
    text-align: center;
    min-height: 28px;
    white-space: normal;
}

.status-pill.full {
    background: var(--success-bg);
    color: #065f46;
}

.status-pill.partial {
    background: var(--warning-bg);
    color: #92400e;
}

.status-pill.unpaid {
    background: #f1f5f9;
    color: #64748b;
}

/* Action Buttons inside Card */
.btn-add-money {
    padding: 6px 12px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--primary-light);
    color: var(--primary);
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.btn-add-money:hover {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}

.payment-qr-card{display:flex;align-items:center;justify-content:space-between;gap:24px;margin-bottom:20px;padding:18px 24px;background:linear-gradient(135deg,#eef2ff,#f8fafc);border:1px solid #c7d2fe;border-radius:var(--radius-lg);box-shadow:var(--shadow-sm)}
.payment-qr-title{color:#3730a3;font-size:1rem;font-weight:800;margin-bottom:6px}.payment-qr-note{color:var(--text-muted);font-size:.88rem;margin-bottom:8px}.payment-qr-owner{color:var(--text-main);font-size:.82rem;font-weight:700}.payment-qr-image{width:116px;height:116px;object-fit:cover;border-radius:12px;background:#fff;padding:5px;box-shadow:0 4px 14px rgba(15,23,42,.12)}
@media(max-width:560px){.payment-qr-card{padding:14px;gap:12px}.payment-qr-image{width:92px;height:92px}.payment-qr-owner{font-size:.72rem}.member-card{padding:12px;gap:8px;align-items:flex-start}.member-avatar{width:44px;height:44px}.member-left{gap:8px}.member-right{width:128px}.member-name{font-size:.88rem}.member-paid{font-size:.76rem}.member-cycle-label{font-size:.64rem}.member-cycle-paid{font-size:.7rem}.btn-add-money{padding:6px 8px;font-size:.74rem}}
@media(max-width:560px){.member-profile-grid{grid-template-columns:1fr}.member-profile-actions .btn{flex:1}}
@media(max-width:560px){.avatar-editor{grid-template-columns:1fr}.avatar-editor-preview{width:64px;height:64px}.avatar-upload-btn{width:100%;justify-content:center}}
.payment-qr-image{cursor:zoom-in}.qr-image-modal{display:none;position:fixed;inset:0;z-index:1000;align-items:center;justify-content:center;background:rgba(15,23,42,.82);padding:20px}.qr-image-modal.active{display:flex}.qr-image-large{max-width:92vw;max-height:90vh;background:#fff;border-radius:16px;padding:10px}.qr-image-close{position:absolute;right:22px;top:18px;border:0;border-radius:50%;font-size:28px;width:42px;height:42px;cursor:pointer}

/* ==========================================================
   EXPENSES TABLE & LIST
   ========================================================== */
.expenses-container {
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

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

.expenses-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.92rem;
}

.expenses-table th {
    background: #f8fafc;
    padding: 14px 18px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--card-border);
}

.expenses-table td {
    padding: 16px 18px;
    border-bottom: 1px solid #f1f5f9;
    color: var(--text-main);
    vertical-align: middle;
}

.expenses-table tr:hover td {
    background: #fbfcfe;
}

.expense-title-cell {
    font-weight: 600;
}

.expense-amount-cell {
    font-weight: 800;
    color: #dc2626;
    font-size: 0.98rem;
}

.expense-cat-badge {
    background: #f1f5f9;
    color: #475569;
    font-size: 0.76rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: var(--radius-full);
}

.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.6;
}

/* ==========================================================
   BUTTONS & FORM CONTROLS
   ========================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    font-family: inherit;
    transition: var(--transition);
}

.btn-primary {
    background: var(--primary-gradient);
    color: #fff;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

.btn-primary:hover {
    box-shadow: 0 6px 16px rgba(79, 70, 229, 0.35);
    transform: translateY(-1px);
}

.btn-success {
    background: var(--success-gradient);
    color: #fff;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.25);
}

.btn-secondary {
    background: #fff;
    border-color: var(--card-border);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.btn-danger {
    background: var(--danger-gradient);
    color: #fff;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-sm);
}

/* Form Styles */
.form-group {
    margin-bottom: 18px;
}

.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 6px;
}

.password-input-wrap {
    position: relative;
    display: block;
    width: 100%;
}

.password-input-wrap .form-control {
    padding-right: 46px;
}

.password-toggle {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    width: 34px;
    height: 34px;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 6px;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.password-toggle svg {
    width: 21px;
    height: 21px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
}

.password-toggle.is-visible::after {
    content: '';
    position: absolute;
    width: 24px;
    height: 2px;
    background: currentColor;
    transform: rotate(-45deg);
    border-radius: 2px;
}

.password-toggle:hover,
.password-toggle:focus-visible {
    color: var(--primary);
    background: var(--bg-light);
    outline: none;
}

.form-control {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: inherit;
    background: #fff;
    color: var(--text-main);
    outline: none;
    transition: var(--transition);
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

/* Quick Amount Pills */
.quick-amounts {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.quick-pill {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-full);
    padding: 4px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.quick-pill:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
}

/* ==========================================================
   MODAL POPUPS
   ========================================================== */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.modal-backdrop.active {
    display: flex;
    opacity: 1;
}

.modal-box {
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid var(--card-border);
    transform: translateY(12px) scale(0.97);
    transition: transform 0.25s ease;
}

.modal-backdrop.active .modal-box {
    transform: translateY(0) scale(1);
}

.confirm-box {
    max-width: 460px;
}

.confirm-message {
    color: var(--text-muted);
    font-size: .94rem;
    line-height: 1.65;
}

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

.modal-title {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.modal-close:hover {
    color: var(--danger);
    background: var(--danger-bg);
}

.modal-body {
    padding: 20px 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--card-border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: #f8fafc;
    border-bottom-left-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-lg);
}

/* History List inside Member Modal */
.payment-history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
    max-height: 220px;
    overflow-y: auto;
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-sm);
}

.history-date {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.history-note {
    font-size: 0.85rem;
    font-weight: 500;
}

.history-amount {
    font-size: 0.95rem;
    font-weight: 700;
    color: #059669;
}

.history-del-btn {
    color: #94a3b8;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    font-size: 0.9rem;
}

.history-del-btn:hover {
    color: var(--danger);
}

/* ==========================================================
   SETTINGS TAB
   ========================================================== */
.settings-grid {
    display: grid;
    grid-template-columns: minmax(520px, 1.35fr) minmax(360px, .9fr);
    gap: 24px;
    align-items: start;
}

.settings-card {
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.settings-card-title {
    font-size: 1.05rem;
    font-weight: 800;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.settings-card-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.cycle-manager-card {
    min-height: 520px;
}

/* Code Snippet Box for Firebase instructions */
.code-box {
    background: #1e293b;
    color: #f1f5f9;
    padding: 14px;
    border-radius: var(--radius-sm);
    font-family: monospace;
    font-size: 0.82rem;
    overflow-x: auto;
    margin: 12px 0;
}

/* ==========================================================
   TOAST NOTIFICATIONS
   ========================================================== */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: #0f172a;
    color: #fff;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    font-size: 0.9rem;
    font-weight: 500;
    min-width: 260px;
    max-width: 400px;
    animation: toastSlideIn 0.3s ease forwards;
}

.toast.success { border-left: 4px solid #10b981; }
.toast.error { border-left: 4px solid #ef4444; }
.toast.info { border-left: 4px solid #0ea5e9; }

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

/* ==========================================================
   RESPONSIVE (MOBILE OPTIMIZATIONS)
   ========================================================== */
.brand-icon{cursor:zoom-in}.logo-image-large{max-width:92vw;max-height:90vh;object-fit:contain;background:#fff;border-radius:16px;padding:14px}

@media (max-width: 768px) {
    .top-sticky-panel { position: static !important; box-shadow: none; }
    .app-header { position: static !important; }
    .app-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 14px;
        padding: 14px 18px;
    }

    .header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .metrics-grid {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .metric-value {
        font-size: 1.35rem;
    }

    .members-grid {
        grid-template-columns: 1fr;
    }

    .nav-tabs-wrapper {
        flex-direction: column;
        align-items: stretch;
    }

    .nav-tabs { width: 100%; display:grid; grid-template-columns:1fr 1fr; gap:6px; overflow:visible; padding-bottom:0; }

    .tab-btn {
        width: 100%;
        text-align: center;
        justify-content: center;
        padding: 10px 12px;
        white-space: normal;
    }

    .nav-tab-actions { width:100%; padding-right:0; }
    .nav-tab-actions .btn { width:100%; justify-content:center; }

    .toolbar-section {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-group {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        align-items: stretch;
    }

    .filter-group .cycle-view-label,
    .filter-group .cycle-view-select {
        grid-column: 1 / -1;
    }

    .filter-group .cycle-view-label {
        margin-bottom: -2px;
    }

    .filter-group .cycle-view-select {
        max-width: none;
        width: 100%;
    }

    .filter-btn {
        width: 100%;
        min-height: 38px;
        padding: 8px 10px;
        border-radius: 10px;
        text-align: center;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .metrics-grid {
        grid-template-columns: 1fr;
    }
}
