:root {
    --bg: #0b0d11;
    --bg-soft: #0f1216;
    --surface: #171b21;
    --surface-2: #1d222a;
    --surface-3: #242a33;
    --border: #262c34;
    --border-soft: #2c333d;
    --text: #e6e8eb;
    --text-muted: #9aa4b2;
    --text-dim: #5b6472;
    --primary: #4da3ff;
    --primary-hover: #6fb6ff;
    --primary-soft: rgba(77, 163, 255, 0.12);
    --danger: #ff6b6b;
    --danger-hover: #ff8787;
    --success: #35c37a;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --transition: 150ms ease;
    --sidebar-w: 240px;
    --topbar-h: 60px;
}

* { box-sizing: border-box; }
html { scrollbar-color: var(--border-soft) var(--bg); }

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    background-image: radial-gradient(circle at top, #131720 0%, var(--bg) 55%);
    background-attachment: fixed;
    color: var(--text);
    margin: 0;
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); }
.container { max-width: 1120px; margin: 0 auto; padding: 28px 28px 60px; }

.icon { width: 18px; height: 18px; flex-shrink: 0; }

/* ================= Public (guest) nav ================= */
.public-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(23, 27, 33, 0.92);
    backdrop-filter: blur(8px);
    padding: 14px 24px;
    position: sticky;
    top: 0;
    z-index: 50;
    border-bottom: 1px solid var(--border);
}
.public-nav .nav-links { display: flex; align-items: center; gap: 10px; }
.public-nav a { text-decoration: none; }

.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    color: #fff;
    font-weight: 700;
    font-size: 17px;
    text-decoration: none;
    letter-spacing: -0.01em;
}
.brand .icon { color: var(--primary); width: 20px; height: 20px; }

.public-nav a:not(.btn) { color: var(--text-muted); padding: 8px 12px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; transition: background var(--transition), color var(--transition); }
.public-nav a:not(.btn):hover { color: #fff; background: var(--surface-2); }

/* ================= App shell (sidebar + topbar) ================= */
.app-shell { display: flex; min-height: 100vh; }

.sidebar-toggle-input { display: none; }
.sidebar-backdrop { display: none; }

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 18px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar .brand { padding: 6px 10px 22px; }

.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side-nav-bottom { flex: 0; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.side-nav a {
    display: flex;
    align-items: center;
    gap: 11px;
    color: var(--text-muted);
    text-decoration: none;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    transition: background var(--transition), color var(--transition);
}
.side-nav a:hover { color: #fff; background: var(--surface-2); }
.side-nav a.active { color: var(--primary); background: var(--primary-soft); }
.side-nav a.active .icon { color: var(--primary); }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    background: rgba(11, 13, 17, 0.85);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    z-index: 40;
}
.nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    color: var(--text);
    width: 36px;
    height: 36px;
    cursor: pointer;
    margin-right: auto;
}
.nav-toggle:hover { background: var(--surface-2); }

.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.topbar-balance { color: var(--success); font-weight: 700; background: var(--surface-2); padding: 6px 12px; border-radius: 999px; }
.topbar-name { color: var(--text-muted); }

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        z-index: 70;
        transform: translateX(-100%);
        transition: transform 200ms ease;
        box-shadow: var(--shadow);
    }
    .nav-toggle { display: inline-flex; }
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 60;
    }
    .sidebar-toggle-input:checked ~ .sidebar-backdrop { display: block; }
    .sidebar-toggle-input:checked ~ .sidebar { transform: translateX(0); }
}

@media (max-width: 640px) {
    .public-nav { padding: 12px 16px; }
    .topbar { padding: 0 16px; }
    .topbar-name { display: none; }
}

/* ================= Layout helpers ================= */
.page-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.page-header h1 { margin: 0; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stat-card .stat-value { font-size: 24px; font-weight: 700; color: #fff; margin-top: 6px; }

.auth-card { max-width: 420px; margin: 48px auto; }
.auth-switch { margin-top: 16px; text-align: center; color: var(--text-muted); font-size: 14px; }

.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tab {
    padding: 9px 16px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color var(--transition);
}
.tab:hover { color: #fff; }
.tab.active { color: #fff; border-bottom-color: var(--primary); }

/* ================= Cards ================= */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; margin-bottom: 18px; box-shadow: var(--shadow); }
.card h2:first-child, .card h3:first-child { margin-top: 0; }

h1, h2, h3 { color: #fff; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { color: var(--text); }
.muted, p.muted { color: var(--text-muted); font-size: 14px; }
hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ================= Tables ================= */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; min-width: 560px; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
th { color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }

/* ================= Forms ================= */
label { display: block; font-size: 13px; color: var(--text-muted); margin-top: 12px; margin-bottom: 4px; font-weight: 500; }
label:first-of-type { margin-top: 0; }

input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-soft);
    background: var(--bg-soft);
    color: #fff;
    font-size: 14px;
    font-family: inherit;
    margin-bottom: 4px;
    transition: border-color var(--transition), box-shadow var(--transition);
}
input:hover, select:hover, textarea:hover { border-color: #3a4350; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input[readonly] { color: var(--text-muted); cursor: pointer; }
input::placeholder { color: var(--text-dim); }

.form-row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.form-row > div { flex: 1; min-width: 180px; }

/* Toggle switch */
.switch-row { display: flex; align-items: center; gap: 12px; cursor: pointer; font-size: 14px; }
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track { position: absolute; inset: 0; background: var(--border-soft); border-radius: 999px; transition: background var(--transition); }
.switch-track::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform var(--transition); }
.switch input:checked ~ .switch-track { background: var(--success); }
.switch input:checked ~ .switch-track::before { transform: translateX(18px); }
.switch input:focus-visible ~ .switch-track { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ================= Buttons ================= */
button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: var(--primary);
    color: #06121f;
    border: none;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
}
button:hover, .btn:hover { background: var(--primary-hover); }
button:active, .btn:active { transform: translateY(1px); }
button:focus-visible, .btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
button:disabled, .btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-danger { background: var(--danger); color: #250606; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-outline { background: transparent; color: var(--text); border: 1px solid var(--border-soft); }
.btn-outline:hover { background: var(--surface-2); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); padding: 8px 10px; }
.btn-ghost:hover { background: var(--surface-2); color: #fff; }

td form { margin: 0; display: inline-block; }
td form + form { margin-left: 6px; }
td button { padding: 7px 12px; font-size: 13px; }

/* Tablo satirlarindaki aksiyon gruplari (orn. admin siparis/borc satirlari) */
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.row-actions form { margin: 0 !important; display: flex !important; gap: 6px; align-items: center; }
.row-actions + .row-actions { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); }
.row-actions button { padding: 6px 12px; font-size: 12.5px; }

/* Kucuk form kontrolleri - hem satir ici aksiyonlarda hem filtre barlarinda kullanilir */
.input-sm, select.input-sm {
    padding: 8px 10px;
    font-size: 13px;
    margin: 0;
}
.row-actions .input-sm, .row-actions select.input-sm { width: auto; }
.row-actions input[type="number"].input-sm { width: 76px; }

/* Filtre formlarinda butonun input'larla ayni hizada durmasi icin: gorunmez ama
   yer kaplayan bir label ile diger sutunlarla ayni yukseklikten baslar */
.form-row .btn-row label { visibility: hidden; }
.form-row .btn-row-buttons { display: flex; gap: 6px; }

/* ================= Alerts ================= */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; display: flex; align-items: center; gap: 10px; }
.alert::before { font-size: 15px; }
.alert-error { background: #3a1f22; color: #ff9a9a; border: 1px solid #5c2b2f; }
.alert-error::before { content: "⚠"; }
.alert-ok { background: #16301f; color: #8be9a3; border: 1px solid #2c5c3d; }
.alert-ok::before { content: "✓"; }

/* ================= Badges ================= */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-pending { background: #3a3320; color: #ffd76b; }
.badge-in_progress { background: #1f2b3a; color: #6bb6ff; }
.badge-completed { background: #16301f; color: #8be9a3; }
.badge-partial { background: #3a2f1f; color: #ffb36b; }
.badge-canceled, .badge-error { background: #3a1f22; color: #ff9a9a; }
.badge-unpaid { background: #3a1f22; color: #ff9a9a; }
.badge-paid { background: #16301f; color: #8be9a3; }
.badge-active { background: #16301f; color: #8be9a3; }
.badge-disabled { background: #3a1f22; color: #ff9a9a; }

.debt { color: var(--danger); font-weight: 700; }
.credit { color: var(--success); font-weight: 700; }

/* ================= Misc ================= */
pre { background: var(--bg-soft) !important; border: 1px solid var(--border); padding: 14px !important; border-radius: var(--radius-sm) !important; overflow-x: auto; font-size: 13px; }
code { font-family: "SFMono-Regular", Consolas, Menlo, monospace; }

::-webkit-scrollbar { height: 10px; width: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-soft); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: #454e5c; }

@media (max-width: 600px) {
    .container { padding: 18px 14px 40px; }
    .card { padding: 16px; }
    th, td { font-size: 13px; padding: 8px; }
    .auth-card { margin: 24px auto; }
}
