/* =====================
   CSS Variables
   ===================== */
:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --success-color: #22c55e;
    --success-bg: #dcfce7;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --warning-color: #f59e0b;
    --text-color: #1f2937;
    --text-muted: #6b7280;
    --bg-color: #f3f4f6;
    --card-bg: #ffffff;
    --border-color: #e5e7eb;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --radius: 8px;
    --radius-sm: 4px;
    --nav-height: 60px;
    --header-height: 56px;
}

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

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
    min-height: 100vh;
    padding-bottom: calc(var(--nav-height) + 20px);
}

/* =====================
   Header
   ===================== */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 16px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow);
}

.header-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    color: var(--text-muted);
    border-radius: var(--radius);
    transition: background-color 0.2s, color 0.2s;
}

.logout-btn:hover {
    background-color: var(--bg-color);
    color: var(--danger-color);
}

/* =====================
   Main Content
   ===================== */
.main-content {
    padding: 16px;
    max-width: 1200px;
    margin: 0 auto;
}

/* =====================
   Bottom Navigation
   ===================== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-around;
    height: var(--nav-height);
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 8px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.75rem;
    transition: color 0.2s;
}

.nav-item svg {
    margin-bottom: 4px;
}

.nav-item.active {
    color: var(--primary-color);
}

.nav-item:hover {
    color: var(--primary-color);
}

/* =====================
   Buttons
   ===================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

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

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

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

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-color);
}

.btn-outline:hover {
    background-color: var(--bg-color);
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

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

.btn-block {
    width: 100%;
}

/* =====================
   Forms
   ===================== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.875rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--card-bg);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-hint {
    display: block;
    margin-top: 4px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

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

.form-actions .btn {
    flex: 1;
}

.checkbox-group {
    margin-top: 8px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.checkbox-label input {
    width: auto;
    margin-right: 8px;
}

/* =====================
   Login Page
   ===================== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-container {
    width: 100%;
    max-width: 400px;
}

.login-card {
    background: var(--card-bg);
    padding: 32px 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header svg {
    color: var(--primary-color);
    margin-bottom: 16px;
}

.login-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.error-message {
    background-color: #fef2f2;
    color: var(--danger-color);
    padding: 12px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 0.875rem;
}

/* =====================
   Page Toolbar
   ===================== */
.page-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}

.year-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.year-selector label {
    font-weight: 500;
}

.year-selector select,
.filter-group select {
    padding: 8px 12px;
    font-size: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--card-bg);
}

.filter-group {
    display: flex;
    gap: 8px;
}

.toolbar-info {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* =====================
   Aidat Table
   ===================== */
.table-container {
    overflow-x: auto;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.aidat-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

.aidat-table th,
.aidat-table td {
    padding: 12px 8px;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
}

.aidat-table th {
    background: var(--bg-color);
    font-weight: 600;
    font-size: 0.875rem;
    position: sticky;
    top: 0;
    z-index: 10;
}

.sticky-col {
    position: sticky;
    left: 0;
    background: var(--card-bg);
    z-index: 5;
    min-width: 100px;
    text-align: left !important;
    padding-left: 16px !important;
}

.aidat-table thead .sticky-col {
    background: var(--bg-color);
    z-index: 15;
}

.daire-cell {
    display: flex;
    flex-direction: column;
}

.daire-no {
    font-weight: 600;
}

.sakin-adi {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.month-header {
    font-size: 0.75rem;
}

.month-cell {
    padding: 8px 4px;
    transition: background-color 0.2s;
}

.month-cell.paid {
    background-color: var(--success-bg);
}

.month-cell.unpaid {
    background-color: #fef2f2;
}

.month-cell.future {
    opacity: 0.5;
}

/* Custom Checkbox */
.checkbox-container {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 8px;
}

.checkbox-container input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.checkmark {
    width: 28px;
    height: 28px;
    background-color: var(--bg-color);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.checkbox-container:hover .checkmark {
    border-color: var(--primary-color);
}

.checkbox-container input:checked ~ .checkmark {
    background-color: var(--success-color);
    border-color: var(--success-color);
}

.checkbox-container input:checked ~ .checkmark::after {
    content: '';
    width: 8px;
    height: 14px;
    border: solid white;
    border-width: 0 3px 3px 0;
    transform: rotate(45deg);
    margin-bottom: 4px;
}

/* =====================
   Summary Card
   ===================== */
.summary-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.summary-card h3 {
    font-size: 1rem;
    margin-bottom: 16px;
    color: var(--text-muted);
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

@media (min-width: 640px) {
    .summary-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.summary-item {
    text-align: center;
}

.summary-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.summary-value {
    font-size: 1.25rem;
    font-weight: 600;
}

.paid-count {
    color: var(--success-color);
}

.unpaid-count {
    color: var(--danger-color);
}

.summary-card.compact {
    padding: 16px;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* =====================
   Category Summary
   ===================== */
.category-summary {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.category-summary h4 {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

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

.category-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

.category-item:last-child {
    border-bottom: none;
}

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

.category-amount {
    font-weight: 500;
}

/* =====================
   Gider Cards
   ===================== */
.gider-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.gider-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

.gider-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.gider-kategori {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--primary-color);
    background: rgba(37, 99, 235, 0.1);
    padding: 2px 8px;
    border-radius: 12px;
}

.gider-tarih {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.gider-body {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.gider-aciklama {
    flex: 1;
    margin-right: 16px;
}

.gider-tutar {
    font-size: 1.125rem;
    font-weight: 600;
    white-space: nowrap;
}

.gider-actions {
    display: flex;
    gap: 8px;
}

/* =====================
   Daire Cards
   ===================== */
.daire-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.daire-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

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

.daire-card .daire-no {
    font-size: 1.125rem;
    font-weight: 600;
}

.daire-aidat {
    font-weight: 500;
    color: var(--success-color);
}

.daire-aidat.default {
    color: var(--text-muted);
}

.daire-sakin {
    color: var(--text-color);
    margin-bottom: 4px;
}

.daire-notlar {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.daire-actions {
    display: flex;
    gap: 8px;
}

.info-card {
    background: rgba(37, 99, 235, 0.05);
    border: 1px solid rgba(37, 99, 235, 0.2);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}

.info-card p {
    margin-bottom: 4px;
}

.small-text {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* =====================
   Debt Styles
   ===================== */
.debt-alert {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}

.debt-alert-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.debt-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--danger-color);
    color: white;
    border-radius: 50%;
    font-weight: bold;
    font-size: 1.25rem;
}

.debt-info {
    display: flex;
    flex-direction: column;
}

.debt-info strong {
    color: var(--danger-color);
}

.debt-info span {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.debt-col {
    min-width: 100px;
    text-align: right !important;
}

.debt-cell {
    text-align: right;
    padding-right: 16px !important;
    cursor: pointer;
}

.debt-cell.has-debt {
    background-color: #fef2f2;
}

.debt-amount {
    font-weight: 600;
    color: var(--danger-color);
}

.debt-months {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: block;
}

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

.debt-total {
    color: var(--danger-color);
}

tr.has-debt .sticky-col {
    border-left: 3px solid var(--danger-color);
}

.daire-cell {
    cursor: pointer;
}

.daire-cell:hover {
    background-color: var(--bg-color);
}

/* Detail Modal Styles */
.modal-body {
    padding: 20px;
}

.detail-section {
    margin-bottom: 20px;
}

.detail-section:last-child {
    margin-bottom: 0;
}

.detail-section h4 {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-row.total {
    border-top: 2px solid var(--border-color);
    margin-top: 8px;
    padding-top: 12px;
    font-size: 1.125rem;
}

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

.detail-value {
    font-weight: 500;
}

.text-danger {
    color: var(--danger-color) !important;
}

.text-success {
    color: var(--success-color) !important;
}

.unpaid-list {
    list-style: none;
    padding: 0;
}

.unpaid-list li {
    padding: 8px 12px;
    background: #fef2f2;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    color: var(--danger-color);
    font-size: 0.875rem;
}

.success-message {
    text-align: center;
    padding: 24px;
    background: var(--success-bg);
    border-radius: var(--radius);
}

.success-message p {
    color: var(--success-color);
    font-weight: 500;
}

.detail-notes {
    background: var(--bg-color);
    padding: 12px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    color: var(--text-muted);
}

.loading-inline {
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
}

/* =====================
   Settings Page
   ===================== */
.settings-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.settings-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.settings-section h3 {
    font-size: 1.125rem;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

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

.about-info p {
    margin-bottom: 8px;
}

.version {
    font-size: 0.75rem;
}

/* =====================
   Modal
   ===================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 200;
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

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

.modal-header h3 {
    font-size: 1.125rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    line-height: 1;
}

.modal-content form {
    padding: 20px;
}

/* =====================
   Empty State
   ===================== */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.empty-state svg {
    color: var(--text-muted);
    margin-bottom: 16px;
}

.empty-state h3 {
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--text-muted);
    margin-bottom: 24px;
}

.empty-state.small {
    padding: 32px 16px;
}

/* =====================
   Loading & Toast
   ===================== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.toast {
    position: fixed;
    bottom: calc(var(--nav-height) + 20px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-color);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    z-index: 250;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
}

.toast.error {
    background: var(--danger-color);
}

/* =====================
   Alert
   ===================== */
.alert {
    background: rgba(37, 99, 235, 0.1);
    border: 1px solid rgba(37, 99, 235, 0.2);
    color: var(--primary-color);
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
}

/* =====================
   Responsive
   ===================== */
@media (max-width: 480px) {
    .page-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-group {
        width: 100%;
    }

    .filter-group select {
        flex: 1;
    }

    .page-toolbar .btn {
        width: 100%;
    }

    .form-actions {
        flex-direction: column;
    }

    .gider-actions,
    .daire-actions {
        flex-direction: column;
    }

    .gider-actions .btn,
    .daire-actions .btn {
        width: 100%;
    }
}
