/* ===== Kamana & Suraj Expense Tracker ===== */

#ks-expense-tracker {
    max-width: 680px;
    margin: 0 auto;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    color: #1a1a2e;
}

/* ===== Cards ===== */
.ks-card {
    background: #ffffff;
    border: 1px solid #e8eaf0;
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

/* ===== Balance Card ===== */
.ks-balance-card {
    background: linear-gradient(135deg, #f8f9ff 0%, #eef2ff 100%);
    border-color: #dce3ff;
}
.ks-balance-header { text-align: center; margin-bottom: 20px; }
.ks-title { margin: 0 0 4px; font-size: 22px; font-weight: 700; color: #1a1a2e; }
.ks-subtitle { font-size: 13px; color: #8891b4; letter-spacing: 0.3px; }

.ks-balance-display {
    display: flex;
    align-items: center;
    background: #fff;
    border-radius: 12px;
    padding: 16px 20px;
    border: 1px solid #dce3ff;
}
.ks-balance-item { flex: 1; text-align: center; }
.ks-balance-divider { width: 1px; height: 40px; background: #dce3ff; margin: 0 16px; }
.ks-name { display: block; font-size: 12px; color: #8891b4; margin-bottom: 4px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.ks-amount { display: block; font-size: 22px; font-weight: 700; color: #1a1a2e; }

.ks-owed-box { margin-top: 14px; padding: 12px 16px; border-radius: 10px; background: #fff8e1; border: 1px solid #ffe082; text-align: center; }
.ks-owed-box p { margin: 0; font-weight: 600; color: #b45309; font-size: 15px; }
.ks-settled-box { margin-top: 14px; padding: 12px 16px; border-radius: 10px; background: #e8f5e9; border: 1px solid #a5d6a7; text-align: center; }
.ks-settled-box p { margin: 0; font-weight: 600; color: #2e7d32; }

/* ===== Section Headers ===== */
.ks-section-header { display: flex; justify-content: space-between; align-items: center; cursor: pointer; user-select: none; }
.ks-section-title { margin: 0 0 16px; font-size: 16px; font-weight: 600; color: #1a1a2e; }
.ks-section-header .ks-section-title { margin-bottom: 0; }
.ks-toggle-icon { font-size: 12px; color: #8891b4; transition: transform 0.2s ease; display: inline-block; }
.ks-toggle-icon.collapsed { transform: rotate(-90deg); }

/* ===== Form ===== */
.ks-form-row { display: flex; gap: 12px; margin-bottom: 12px; }
.ks-form-row .ks-field { flex: 1; margin-bottom: 0; }
.ks-field { margin-bottom: 12px; }
.ks-field label { display: block; font-size: 13px; font-weight: 500; color: #5c6380; margin-bottom: 6px; }
.ks-optional { color: #aab0cc; font-weight: 400; }
.ks-required { color: #e53935; }

.ks-field input,
.ks-field select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #e0e3ef;
    border-radius: 10px;
    font-size: 15px;
    color: #1a1a2e;
    background: #fafbff;
    box-sizing: border-box;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}
.ks-field input:focus,
.ks-field select:focus {
    border-color: #5c6ef8;
    box-shadow: 0 0 0 3px rgba(92,110,248,0.12);
    background: #fff;
}

/* ===== Toggle group ===== */
.ks-toggle-group { display: flex; gap: 8px; }
.ks-toggle { flex: 1; padding: 10px 12px; border: 1px solid #e0e3ef; border-radius: 10px; background: #fafbff; color: #8891b4; font-size: 14px; font-weight: 500; cursor: pointer; transition: all 0.15s ease; }
.ks-toggle:hover { border-color: #5c6ef8; color: #5c6ef8; }
.ks-toggle.active { background: #5c6ef8; border-color: #5c6ef8; color: #fff; box-shadow: 0 2px 8px rgba(92,110,248,0.3); }

/* ===== Buttons ===== */
.ks-btn { display: flex; align-items: center; justify-content: center; padding: 12px 24px; border-radius: 10px; font-size: 15px; font-weight: 600; cursor: pointer; border: none; transition: all 0.15s ease; width: 100%; margin-top: 4px; }
.ks-btn-primary { background: #5c6ef8; color: #fff; }
.ks-btn-primary:hover { background: #4a5ce6; box-shadow: 0 4px 12px rgba(92,110,248,0.35); }
.ks-btn-primary:disabled { background: #aab0e8; cursor: not-allowed; }
.ks-btn-danger { background: #fff; color: #e53935; border: 1.5px solid #ffcdd2; }
.ks-btn-danger:hover { background: #ffebee; border-color: #e53935; box-shadow: 0 4px 12px rgba(229,57,53,0.15); }

.ks-btn-ghost {
    background: none;
    border: 1.5px solid #5c6ef8;
    color: #5c6ef8;
    padding: 9px 18px;
    border-radius: 9px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
}
.ks-btn-ghost:hover { background: #eef2ff; }

.ks-btn-ghost-sm {
    background: none;
    border: 1px solid #5c6ef8;
    color: #5c6ef8;
    padding: 7px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}
.ks-btn-ghost-sm:hover { background: #eef2ff; }
.ks-btn-ghost-sm.ks-muted { border-color: #ccc; color: #888; }
.ks-btn-ghost-sm.ks-muted:hover { background: #f5f5f5; }

/* ===== Expense list ===== */
.ks-history-list { margin-top: 16px; max-height: 420px; overflow-y: auto; padding-right: 4px; }
.ks-history-list::-webkit-scrollbar { width: 5px; }
.ks-history-list::-webkit-scrollbar-track { background: transparent; }
.ks-history-list::-webkit-scrollbar-thumb { background: #dce3ff; border-radius: 99px; }
.ks-history-list::-webkit-scrollbar-thumb:hover { background: #b0bcf8; }
.ks-empty-state { text-align: center; color: #aab0cc; font-size: 14px; padding: 20px 0; margin: 0; }

.ks-expense-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid #f0f2f9; }
.ks-expense-item:last-child { border-bottom: none; }
.ks-expense-icon { font-size: 20px; width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; background: #f0f2ff; border-radius: 10px; flex-shrink: 0; }
.ks-expense-info { flex: 1; min-width: 0; }
.ks-expense-category { font-weight: 600; font-size: 14px; color: #1a1a2e; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ks-expense-desc { font-size: 12px; color: #8891b4; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ks-expense-date { font-size: 11px; color: #aab0cc; margin-top: 2px; }
.ks-expense-meta { text-align: right; flex-shrink: 0; }
.ks-expense-amount { font-weight: 700; font-size: 15px; color: #1a1a2e; }
.ks-expense-payer { font-size: 12px; color: #8891b4; margin-top: 2px; }

.ks-delete-btn { background: none; border: none; color: #ccc; font-size: 16px; cursor: pointer; padding: 4px; border-radius: 6px; line-height: 1; flex-shrink: 0; transition: color 0.15s, background 0.15s; }
.ks-delete-btn:hover { color: #e53935; background: #ffebee; }

/* ===== Settle Card ===== */
.ks-settle-card { border-color: #fce4e4; background: #fffafa; }
.ks-settle-desc { font-size: 13px; color: #8891b4; margin: -8px 0 16px; }

/* ===== History CTA ===== */
.ks-history-cta { background: #f8f9ff; border-color: #dce3ff; }
.ks-history-cta-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ks-history-cta-title { font-weight: 600; font-size: 15px; color: #1a1a2e; }
.ks-history-cta-sub { font-size: 13px; color: #8891b4; margin-top: 2px; }

/* ===== Modal ===== */
.ks-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 99999;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 16px 16px;
    overflow-y: auto;
    backdrop-filter: blur(2px);
}
.ks-modal {
    background: #fff;
    border-radius: 20px;
    width: 100%;
    max-width: 660px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.18);
    overflow: hidden;
    flex-shrink: 0;
}
.ks-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid #f0f2f9;
}
.ks-modal-header h3 { margin: 0; font-size: 17px; font-weight: 700; color: #1a1a2e; }
.ks-modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: #8891b4; padding: 4px 8px; border-radius: 8px; transition: background 0.15s, color 0.15s; }
.ks-modal-close:hover { background: #f0f2f9; color: #1a1a2e; }

.ks-modal-filters { padding: 16px 24px; background: #fafbff; border-bottom: 1px solid #f0f2f9; }
.ks-filter-row { display: flex; gap: 12px; margin-bottom: 10px; }
.ks-filter-row:last-child { margin-bottom: 0; }
.ks-filter-field { flex: 1; }
.ks-filter-field label { display: block; font-size: 12px; font-weight: 500; color: #8891b4; margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.4px; }
.ks-filter-field input,
.ks-filter-field select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #e0e3ef;
    border-radius: 8px;
    font-size: 14px;
    color: #1a1a2e;
    background: #fff;
    box-sizing: border-box;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}
.ks-filter-field input:focus,
.ks-filter-field select:focus { border-color: #5c6ef8; box-shadow: 0 0 0 3px rgba(92,110,248,0.1); }

.ks-filter-actions { display: flex; gap: 8px; margin-top: 12px; }

.ks-modal-summary {
    display: flex;
    gap: 16px;
    padding: 12px 24px;
    background: #f0f2ff;
    border-bottom: 1px solid #dce3ff;
    font-size: 13px;
    color: #5c6380;
    flex-wrap: wrap;
}
.ks-modal-summary strong { color: #1a1a2e; }

.ks-modal-body { padding: 8px 24px 24px; max-height: 55vh; overflow-y: auto; }

/* cycle label inside modal */
.ks-cycle-label {
    font-size: 11px;
    font-weight: 600;
    color: #8891b4;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    padding: 12px 0 4px;
    border-top: 1px solid #f0f2f9;
    margin-top: 4px;
}
.ks-cycle-label:first-child { border-top: none; margin-top: 0; }

/* ===== Error ===== */
.ks-error { font-size: 13px; color: #e53935; margin: 8px 0 0; text-align: center; }

/* ===== Utility ===== */
.ks-hidden { display: none !important; }

/* ===== Responsive ===== */
@media (max-width: 480px) {
    .ks-card { padding: 18px; }
    .ks-form-row, .ks-filter-row { flex-direction: column; }
    .ks-balance-display { padding: 14px 12px; }
    .ks-amount { font-size: 18px; }
    .ks-modal-overlay { padding: 0; align-items: flex-end; }
    .ks-modal { border-radius: 20px 20px 0 0; }
    .ks-modal-body { max-height: 50vh; }
    .ks-history-cta-inner { flex-direction: column; align-items: flex-start; gap: 10px; }
}
