:root {
    --color-bg: #f4f5f7;
    --color-surface: #ffffff;
    --color-border: #e2e4e9;
    --color-text: #1f2430;
    --color-text-muted: #6b7280;
    --color-primary: #b8121a;
    --color-primary-dark: #8f0e14;
    --color-primary-soft: #fdeaea;
    --color-green: #1c7c3f;
    --color-green-soft: #e7f6ec;
    --color-blue: #1b5fad;
    --color-blue-soft: #e8f0fb;
    --color-gray-soft: #eceef1;
    --color-red: #b8121a;
    --color-red-soft: #fdeaea;
    --topnav-height: 64px;
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: Tahoma, Verdana, "Segoe UI", Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 10pt;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 12px; font-weight: 600; }
h1 { font-size: 1.6em; }
h2 { font-size: 1.35em; }
h3 { font-size: 1.15em; }

/* --- Auth (login) sayfası --- */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1f2430, #3a2226);
    padding: 20px;
}
.auth-card {
    background: var(--color-surface);
    border-radius: 12px;
    padding: 40px 36px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 20px 50px rgba(0,0,0,.25);
    text-align: center;
}
.auth-card img.logo { height: 42px; margin-bottom: 20px; }
.auth-card h1 { font-size: 1em; color: var(--color-text-muted); font-weight: 500; margin-bottom: 24px; }
.auth-card .field { text-align: left; margin-bottom: 16px; }

/* --- Layout --- */
.app-layout { display: flex; flex-direction: column; min-height: 100vh; }

.topnav {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 20px;
    background: #ffffff;
    border-bottom: 1px solid var(--color-border);
    padding: 0 28px;
    height: var(--topnav-height);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
}
.topnav .brand { display: flex; align-items: center; flex-shrink: 0; justify-self: start; }
.topnav .brand img { height: 30px; display: block; }
.nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
}
.topnav nav {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-self: center;
    max-width: 100%;
    overflow-x: auto;
}
.topnav nav a {
    display: flex;
    align-items: center;
    padding: 9px 16px;
    border-radius: 6px;
    color: #4b5563;
    font-size: 1em;
    white-space: nowrap;
}
.topnav nav a:hover { background: var(--color-gray-soft); text-decoration: none; }
.topnav nav a.active { background: var(--color-primary); color: #fff; }
.topnav nav a.nav-logout { display: none; }
.topnav .user-box {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
    justify-self: end;
    padding-left: 20px;
    border-left: 1px solid var(--color-border);
}
.topnav .user-box .user-info { white-space: nowrap; }
.topnav .user-box .name { color: var(--color-text); font-weight: 600; font-size: 1em; }
.topnav .user-box .role { color: var(--color-text-muted); font-size: 1em; margin-left: 3px; }
.topnav .user-box .logout-link {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--color-primary);
    font-weight: 700;
    font-size: 1em;
    white-space: nowrap;
}
.topnav .user-box .logout-link svg { flex-shrink: 0; }
.topnav .user-box-divider { width: 1px; height: 18px; background: var(--color-border); flex-shrink: 0; }

.main {
    flex: 1;
    margin-top: var(--topnav-height);
    padding: 28px 32px;
    max-width: 100%;
    overflow-x: auto;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
}
.topbar h1 { font-size: 1.6em; }

/* --- Kartlar / tablolar --- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}

.dashboard-grid { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.dashboard-grid > .card { flex: 1 1 380px; min-width: 280px; }

.card-centered { margin-left: auto; margin-right: auto; }

.totals-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--color-border);
    font-size: 1em;
}
.totals-line:last-child { border-bottom: none; }

/* --- Panel (dashboard) --- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.kpi-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 18px 20px;
}
.kpi-value { font-size: 1.6em; font-weight: 700; color: var(--color-text); margin-bottom: 4px; }
.kpi-label { font-size: 1em; color: var(--color-text-muted); }
.chart-svg { width: 100%; height: auto; max-width: 560px; }

table { width: 100%; border-collapse: collapse; font-size: 1em; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
th { color: var(--color-text-muted); font-weight: 600; font-size: 1em; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:hover { background: #fafbfc; }
.table-wrap { overflow-x: auto; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 1em; font-weight: 600; }
.badge-gray { background: var(--color-gray-soft); color: #4b5563; }
.badge-blue { background: var(--color-blue-soft); color: var(--color-blue); }
.badge-green { background: var(--color-green-soft); color: var(--color-green); }
.badge-red { background: var(--color-red-soft); color: var(--color-red); }

/* --- Formlar --- */
label { display: block; font-size: 1em; font-weight: 600; margin-bottom: 6px; color: #3a3f4b; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=datetime-local], input[type=number], input[type=search], select, textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 1em;
    font-family: inherit;
    background: #fff;
    color: var(--color-text);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-soft);
}
textarea { resize: vertical; min-height: 80px; }
textarea.autogrow { resize: none; overflow: hidden; min-height: 48px; }
.field { margin-bottom: 16px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.hint { font-size: 6pt; color: var(--color-text-muted); margin-top: 4px; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: 6px;
    border: 1px solid var(--color-border);
    background: #fff;
    color: var(--color-text);
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}
.btn:hover { background: #f5f6f8; text-decoration: none; }
.btn-primary { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-danger { color: var(--color-red); border-color: #f3c9cb; }
.btn-danger:hover { background: var(--color-red-soft); }
.btn-sm { padding: 5px 12px; font-size: 1em; }
.btn-block { width: 100%; justify-content: center; }
.btn-row { display: flex; gap: 10px; margin-top: 20px; }

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

/* --- Uyarılar --- */
.alert { padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 1em; }
.alert-success { background: var(--color-green-soft); color: var(--color-green); }
.alert-error { background: var(--color-red-soft); color: var(--color-red); }
.alert-info { background: var(--color-blue-soft); color: var(--color-blue); }

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

/* --- Teklif kalem tablosu --- */
.items-table { table-layout: fixed; width: 100%; }
.items-table input { padding: 7px 8px; font-size: 1em; width: 100%; box-sizing: border-box; }
.items-table td { padding: 6px; }
.items-table th:nth-child(1), .items-table td:nth-child(1) { width: 52%; }
.items-table th:nth-child(2), .items-table td:nth-child(2) { width: 18%; }
.items-table th:nth-child(3), .items-table td:nth-child(3) { width: 10%; }
.items-table th:nth-child(4), .items-table td:nth-child(4) { width: 20%; }

.items-table .desc-input { min-width: 0; }
.items-table .num-input { text-align: right; }
.items-table .row-total { text-align: right; font-weight: 600; white-space: nowrap; }
.items-table tbody tr { cursor: context-menu; }

.items-table .currency-input { position: relative; display: flex; align-items: center; }
.items-table .currency-input-symbol {
    position: absolute; left: 9px; color: var(--color-text-muted); font-size: 1em; pointer-events: none;
}
.items-table .currency-input input { padding-left: 20px; }

.items-table tfoot .totals-row td {
    border-top: 1px solid var(--color-border); border-bottom: none;
    padding: 12px 6px; font-size: 1em; font-weight: 700;
}
.items-table tfoot .totals-row td:first-child { color: var(--color-text-muted); font-weight: 600; font-size: 1em; }

.row-context-menu {
    position: fixed; z-index: 1000; background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.15); padding: 4px; min-width: 100px;
}
.row-context-menu button {
    display: block; width: 100%; text-align: left; padding: 7px 10px; background: none; border: none;
    color: var(--color-red); font-size: 1em; cursor: pointer; border-radius: 4px; font-family: inherit;
}
.row-context-menu button:hover { background: var(--color-red-soft); }

.text-muted { color: var(--color-text-muted); }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }

.revision-chip { font-size: 1em; padding: 2px 8px; border-radius: 999px; background: var(--color-gray-soft); color: #4b5563; margin-left: 6px; }

/* =====================================================================
   Panel & Ajanda — modern tasarım (yalnızca bu iki sayfada kullanılan
   sınıflar: .dashboard-grid, .kpi-*, .calendar-*, .agenda-detail-*,
   .timeline-*, .icon-btn — diğer sayfalarda referans edilmiyor).
   ===================================================================== */

.dashboard-grid > .card {
    border: 1px solid rgba(15, 23, 42, .05);
    border-radius: 16px;
    box-shadow: 0 1px 2px rgba(16,24,40,.04), 0 8px 20px -6px rgba(16,24,40,.07);
    padding: 22px;
}
.dashboard-grid h3 { font-size: 1.05em; letter-spacing: -.01em; }

.kpi-grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.kpi-card {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--color-surface);
    border: 1px solid rgba(15, 23, 42, .05);
    border-radius: 16px;
    padding: 16px 18px;
    box-shadow: 0 1px 2px rgba(16,24,40,.04), 0 8px 20px -6px rgba(16,24,40,.07);
}
.kpi-icon {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.kpi-icon svg { width: 22px; height: 22px; }
.kpi-icon-red { background: var(--color-primary-soft); color: var(--color-primary); }
.kpi-icon-blue { background: var(--color-blue-soft); color: var(--color-blue); }
.kpi-icon-green { background: var(--color-green-soft); color: var(--color-green); }
.kpi-value { font-size: 1.5em; font-weight: 700; letter-spacing: -.01em; line-height: 1.15; margin-bottom: 1px; }
.kpi-label { font-size: 0.92em; color: var(--color-text-muted); }

/* Zaman çizelgesi listesi (Son Aktiviteler / Yaklaşan Ajanda) */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline-item { position: relative; display: flex; gap: 12px; padding: 0 0 16px 0; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-rail {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 10px;
}
.timeline-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--color-primary); margin-top: 5px; flex-shrink: 0; }
.timeline-line { width: 1px; flex: 1; background: var(--color-border); margin-top: 4px; }
.timeline-item:last-child .timeline-line { display: none; }
.timeline-body { flex: 1; min-width: 0; padding-bottom: 2px; }
.timeline-title { font-size: 1em; color: var(--color-text); }
.timeline-title strong { font-weight: 600; }
.timeline-meta { font-size: 0.85em; color: var(--color-text-muted); margin-top: 2px; }

/* Takvim */
.agenda-content-center { display: flex; justify-content: center; }
.agenda-content-center > .dashboard-grid { width: fit-content; flex-wrap: nowrap; }
.dashboard-grid > .calendar-card { flex: 0 0 auto; max-width: 460px; padding: 30px 34px; }
.dashboard-grid > .agenda-detail-card { flex: 0 0 520px; }
.calendar-nav { display: flex; align-items: center; justify-content: space-between; max-width: 370px; margin: 0 auto 22px; }
.calendar-nav .calendar-month-label { font-size: 1.3em; font-weight: 700; letter-spacing: -.01em; }
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    text-decoration: none;
    cursor: pointer;
    font-family: inherit;
    padding: 0;
    transition: background-color .12s, border-color .12s, color .12s;
}
.icon-btn svg { width: 21px; height: 21px; }
.icon-btn-danger:hover { background: var(--color-red-soft); border-color: #f3c9cb; color: var(--color-red); }
.icon-btn:hover { background: var(--color-gray-soft); border-color: var(--color-border); text-decoration: none; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 9px; max-width: 370px; margin: 0 auto; }
.calendar-grid.calendar-head { margin: 0 auto 12px; }
.calendar-weekday { text-align: center; font-size: 0.95em; font-weight: 700; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: .04em; padding: 2px 0; }
.calendar-day {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1 / 1;
    width: 100%;
    border-radius: 50%;
    padding: 1px;
    background: transparent;
    text-decoration: none;
    transition: background-color .12s;
}
.calendar-day:hover { background: var(--color-gray-soft); text-decoration: none; }
.calendar-day-today { background: var(--color-blue-soft); }
.calendar-day-selected { background: var(--color-green-soft); }
.calendar-day-empty { background: transparent; }
.calendar-day-empty:hover { background: transparent; }
.calendar-day-num { font-size: 1.05em; font-weight: 600; color: var(--color-text); }
.calendar-day-has-items .calendar-day-num { color: var(--color-primary); font-weight: 700; }

.agenda-detail-item { display: flex; gap: 15px; padding: 18px 0; border-bottom: 1px solid var(--color-border); }
.agenda-detail-item:last-of-type { border-bottom: none; padding-bottom: 0; }
.agenda-detail-time {
    flex-shrink: 0;
    width: 70px;
    text-align: center;
    font-size: 1.05em;
    font-weight: 700;
    color: var(--color-primary);
    background: var(--color-primary-soft);
    border-radius: 12px;
    padding: 8px 5px;
    align-self: flex-start;
}
.agenda-detail-body { flex: 1; min-width: 0; }
.agenda-detail-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 2px; }
.agenda-detail-title { font-weight: 600; margin-bottom: 2px; }
.agenda-detail-actions { display: flex; gap: 6px; flex-shrink: 0; }

@media (max-width: 860px) {
    .topnav { grid-template-columns: auto 1fr auto; gap: 8px; padding: 0 14px; }
    .topnav .user-box .logout-link { display: none; }
    .topnav .user-box .name { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .topnav .user-box { border-left: none; padding-left: 0; gap: 10px; }
    .main { padding: 18px; }
    .dashboard-grid > .card { flex-basis: 100%; }
    .agenda-content-center > .dashboard-grid { flex-wrap: wrap; }
    .dashboard-grid > .calendar-card,
    .dashboard-grid > .agenda-detail-card { max-width: 100%; }
    .topbar { flex-wrap: wrap; gap: 10px; }
    .topbar .actions-cell { flex-wrap: wrap; }

    .items-table { font-size: 0.9em; }
    .items-table th:nth-child(1), .items-table td:nth-child(1) { width: 38%; }
    .items-table th:nth-child(2), .items-table td:nth-child(2) { width: 24%; }
    .items-table th:nth-child(3), .items-table td:nth-child(3) { width: 12%; }
    .items-table th:nth-child(4), .items-table td:nth-child(4) { width: 26%; }
    .items-table td.num, .items-table th.num { overflow-wrap: break-word; word-break: break-word; }

    .nav-toggle { display: flex; }
    .topnav nav {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        justify-self: stretch;
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 2px;
        background: var(--color-surface);
        border-bottom: 1px solid var(--color-border);
        box-shadow: 0 8px 16px rgba(0,0,0,.08);
        padding: 8px;
        overflow-x: visible;
        max-width: none;
    }
    .topnav nav.open { display: flex; }
    .topnav nav a { padding: 12px 14px; }
    .topnav nav a.nav-logout {
        display: flex;
        gap: 8px;
        border-top: 1px solid var(--color-border);
        margin-top: 4px;
        padding-top: 14px;
        color: var(--color-primary);
        font-weight: 700;
    }
    .topnav nav a.nav-logout svg { flex-shrink: 0; }

    .table-cards thead { display: none; }
    .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
    .table-cards tr {
        background: var(--color-surface);
        border: 1px solid var(--color-border);
        border-radius: 8px;
        padding: 4px 14px;
        margin-bottom: 12px;
    }
    .table-cards td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        text-align: right;
        padding: 10px 0;
        border-bottom: 1px solid var(--color-border);
    }
    .table-cards td:last-child { border-bottom: none; }
    .table-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--color-text-muted);
        text-align: left;
        flex-shrink: 0;
    }
    .table-cards td:empty,
    .table-cards td:not([data-label]):not(.actions-cell) { display: none; }
    .table-cards td.actions-cell {
        justify-content: flex-end;
        flex-wrap: wrap;
    }
    .table-cards td.actions-cell::before { display: none; }
}
