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

:root {
    --primary: #2c5282;
    --primary-dark: #1a365d;
    --accent: #38a169;
    --accent-dark: #2f855a;
    --danger: #e53e3e;
    --warning: #d69e2e;
    --text: #1a202c;
    --text-light: #718096;
    --bg: #f7fafc;
    --card: #fff;
    --border: #e2e8f0;
    --sidebar-bg: #1a365d;
    --sidebar-text: #cbd5e0;
    --sidebar-active-bg: #2c5282;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.08);
}

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

/* App layout */
.app {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 24px 0;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    margin-bottom: 16px;
}

.sidebar-brand .brand-mark {
    width: 36px; height: 36px;
    background: var(--accent);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-weight: bold;
    color: white;
}

.sidebar-brand .brand-text {
    color: white;
    font-weight: 600;
    font-size: 16px;
}

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

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 8px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 14px;
    transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
    background: rgba(255,255,255,0.06);
    color: white;
}

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

.nav-icon { font-size: 16px; }
.nav-label { font-weight: 500; }

.sidebar-footer {
    padding: 16px 16px 0;
    border-top: 1px solid rgba(255,255,255,0.1);
    margin-top: auto;
    font-size: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-footer #user-email { color: rgba(255,255,255,0.6); }

.logout-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.2);
    color: white;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
}

.logout-btn:hover {
    background: rgba(255,255,255,0.1);
}

.main {
    padding: 24px 32px;
    overflow-x: hidden;
}

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

.page-header h1 {
    font-size: 24px;
    color: var(--text);
}

.btn {
    padding: 9px 16px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: var(--primary);
    color: white;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s, transform 0.05s;
}

.btn:hover { background: var(--primary-dark); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-secondary {
    background: white;
    color: var(--text);
    border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg); }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #c53030; }

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

.btn-icon {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.btn-icon:hover { background: var(--bg); }
.btn-icon.danger:hover { background: #fff5f5; color: var(--danger); border-color: var(--danger); }

/* Cards */
.card {
    background: var(--card);
    border-radius: 10px;
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.card-title {
    font-size: 14px;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
    font-weight: 600;
}

/* Forms */
.form-grid {
    display: grid;
    gap: 14px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

label.field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

label.field small {
    font-weight: 400;
    color: var(--text-light);
    font-size: 12px;
}

input, select, textarea {
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    background: white;
    outline: none;
    transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
}

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

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

.form-status {
    font-size: 13px;
    color: var(--accent);
    margin-top: 8px;
}

.form-status.error { color: var(--danger); }

/* Tables */
.table-wrap {
    overflow-x: auto;
    background: white;
    border-radius: 10px;
    box-shadow: var(--shadow);
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table thead { background: var(--bg); }

.table th {
    text-align: left;
    padding: 10px 14px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 1px solid var(--border);
}

.table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #fafbfc; }

.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { white-space: nowrap; width: 1%; text-align: right; }

.muted { color: var(--text-light); }

.balance-row {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    font-size: 13px;
    line-height: 1.4;
}

.balance-row.balance-positive { color: var(--accent-dark); }
.balance-row.balance-negative { color: var(--danger); }

/* Badges & status */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-alacak { background: #c6f6d5; color: #22543d; }
.badge-borc   { background: #fed7d7; color: #742a2a; }
.badge-paid   { background: #e2e8f0; color: #4a5568; }
.badge-due    { background: #feebc8; color: #7b341e; }

.badge-cari-type {
    background: #e2e8f0;
    color: #2d3748;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-backdrop {
    position: absolute; inset: 0;
    background: rgba(26, 54, 93, 0.6);
}

.modal-content {
    position: relative;
    background: white;
    border-radius: 10px;
    width: 100%;
    max-width: 620px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

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

.modal-header h2 { font-size: 18px; }

.modal-close {
    background: transparent;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--text-light);
    width: 30px; height: 30px;
    border-radius: 50%;
    line-height: 1;
}

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

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

/* Login */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.login-card {
    background: white;
    border-radius: 12px;
    padding: 36px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.login-card .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    margin-bottom: 24px;
}

.login-card h1 {
    font-size: 20px;
    text-align: center;
    color: var(--text);
    margin-bottom: 24px;
}

.login-card form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.login-card .login-error {
    color: var(--danger);
    font-size: 13px;
    text-align: center;
    margin-top: 8px;
}

/* Dashboard summary cards */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.summary-card {
    background: white;
    border-radius: 10px;
    padding: 16px 18px;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--primary);
}

.summary-card.alacak { border-left-color: var(--accent); }
.summary-card.borc   { border-left-color: var(--danger); }
.summary-card.bank   { border-left-color: var(--primary); }

.summary-card .label {
    font-size: 12px;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    font-weight: 600;
}

.summary-card .amounts {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.summary-card .amount {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.summary-card .amount.zero { color: var(--text-light); font-weight: 400; }

/* Two-column layout for forms */
.split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

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

/* Map picker */
.map-picker {
    width: 100%;
    height: 280px;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    z-index: 1;
}

.coords-display {
    color: var(--text-light);
    font-family: ui-monospace, SFMono-Regular, monospace;
    font-size: 12px;
    margin-top: 6px;
}

.link-btn {
    background: transparent;
    border: none;
    color: var(--danger);
    cursor: pointer;
    text-decoration: underline;
    padding: 0;
    font-size: 12px;
}

/* Cari contacts list (in form) */
.contacts-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.contact-row {
    display: grid;
    grid-template-columns: 2fr 1.5fr 1.5fr 1.5fr 30px;
    gap: 8px;
    align-items: start;
}

@media (max-width: 700px) {
    .contact-row { grid-template-columns: 1fr; }
}

.add-contact-btn {
    background: var(--bg);
    border: 1px dashed var(--border);
    color: var(--text-light);
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    width: 100%;
}

.add-contact-btn:hover { background: white; color: var(--primary); }

/* Mobile sidebar */
@media (max-width: 800px) {
    .app { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: auto;
        flex-direction: row;
        padding: 6px 4px;
        z-index: 50;
        top: auto;
    }
    .sidebar-brand, .sidebar-footer { display: none; }
    .sidebar-nav {
        flex-direction: row;
        flex: 1;
        justify-content: space-around;
        padding: 0;
    }
    .nav-item {
        flex-direction: column;
        gap: 2px;
        padding: 6px;
        font-size: 10px;
    }
    .nav-label { font-size: 10px; }
    .main { padding: 16px; padding-bottom: 80px; }
}

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

.calendar-header h2 { font-size: 17px; }

.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.cal-header {
    text-align: center;
    font-size: 11px;
    color: var(--text-light);
    text-transform: uppercase;
    font-weight: 600;
    padding: 6px 0;
}

.cal-day {
    position: relative;
    aspect-ratio: 1;
    background: var(--bg);
    border-radius: 6px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    font-size: 13px;
    overflow: hidden;
}

.cal-day .day-num {
    font-weight: 500;
    color: var(--text);
}

.cal-day.empty { background: transparent; }
.cal-day.today { background: #ebf4ff; box-shadow: inset 0 0 0 2px var(--primary); }
.cal-day.selected { background: var(--primary); color: white; }
.cal-day.selected .day-num { color: white; }
.cal-day.has-items { cursor: pointer; }
.cal-day.has-items:hover { background: #e6f0ff; }

.cal-day .day-totals {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 1px;
    font-size: 10px;
    font-weight: 600;
}

.cal-day .alacak-total { color: var(--accent-dark); }
.cal-day .borc-total   { color: var(--danger); }

.cal-day.selected .alacak-total,
.cal-day.selected .borc-total { color: white; }

.day-detail {
    margin-top: 16px;
    padding: 16px;
    background: var(--bg);
    border-radius: 8px;
}

.day-detail h3 {
    font-size: 14px;
    color: var(--text);
    margin-bottom: 10px;
}

.day-detail-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.day-detail-item {
    background: white;
    border-radius: 6px;
    padding: 10px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}

.day-detail-item .info { flex: 1; min-width: 0; }
.day-detail-item .info .cari { font-weight: 500; }
.day-detail-item .info .desc { font-size: 12px; color: var(--text-light); }

.day-detail-item .amount { font-weight: 600; font-variant-numeric: tabular-nums; }
.day-detail-item .amount.alacak { color: var(--accent-dark); }
.day-detail-item .amount.borc   { color: var(--danger); }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
}

.empty-state p { margin-bottom: 12px; }
