:root {
    --bg: #f5f7fa;
    --surface: #ffffff;
    --border: #e3e8ef;
    --text: #1f2937;
    --text-muted: #6b7280;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --ok: #16a34a;
    --warn: #d97706;
    --sidebar-w: 240px;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3 { margin: 0 0 .5rem; font-weight: 600; color: var(--text); }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }
p { margin: 0 0 1rem; }
code { background: #eef2f7; padding: 1px 6px; border-radius: 4px; font-size: 0.9em; }
.muted { color: var(--text-muted); }
.ta-r { text-align: right; }

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

.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    transform: translateX(0);
    transition: transform 0.2s ease;
}

.brand {
    display: flex; align-items: center; gap: .6rem;
    padding: 1.1rem 1.2rem;
    border-bottom: 1px solid var(--border);
}
.brand-mark {
    width: 32px; height: 32px;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .85rem;
}
.brand-text { font-weight: 600; }

.nav { display: flex; flex-direction: column; padding: .6rem; flex: 1; gap: 2px; }
.nav-item {
    display: block;
    padding: .55rem .8rem;
    color: var(--text);
    border-radius: 6px;
    font-size: .95rem;
}
.nav-item:hover { background: #eef2f7; text-decoration: none; }
.nav-item.is-active {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary);
    font-weight: 500;
}

.sidebar-foot {
    padding: 1rem 1.2rem;
    border-top: 1px solid var(--border);
    font-size: .9rem;
}
.user { color: var(--text-muted); margin-bottom: .3rem; }
.logout { color: var(--danger); }
.logout:hover { color: var(--danger-hover); }

/* Language switcher */
.lang-switch {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 999px;
    overflow: hidden;
    margin-top: .75rem;
    font-size: .8rem;
}
.lang-switch-centered {
    display: flex;
    justify-content: center;
    margin-top: 1.2rem;
    width: fit-content;
    margin-left: auto;
    margin-right: auto;
}
.lang-switch-item {
    padding: .35rem .85rem;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    border-right: 1px solid var(--border);
    background: var(--surface);
    line-height: 1;
}
.lang-switch-item:last-child { border-right: none; }
.lang-switch-item:hover { background: #eef2f7; text-decoration: none; }
.lang-switch-item.is-active {
    background: var(--primary);
    color: #fff;
}
.lang-switch-item.is-active:hover { background: var(--primary-hover); }

.main {
    flex: 1;
    margin-left: var(--sidebar-w);
    min-width: 0;
}

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.5rem;
    display: flex; align-items: center; gap: 1rem;
}
.topbar-title { margin: 0; }

.content { padding: 1.5rem; max-width: 1100px; }

/* Cards (dashboard) */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.2rem;
    box-shadow: var(--shadow);
}
.card-label { color: var(--text-muted); font-size: .85rem; margin-bottom: .4rem; }
.card-value { font-size: 1.8rem; font-weight: 600; }
.card-value-sm { font-size: 1.05rem; }

/* Panels */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.2rem 1.4rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}
.actions { display: flex; flex-wrap: wrap; gap: .6rem; }

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    align-items: end;
}
.form-grid .form-actions { grid-column: 1 / -1; }

.form-stack { display: flex; flex-direction: column; gap: .9rem; }

label > span {
    display: block;
    font-size: .85rem;
    color: var(--text-muted);
    margin-bottom: .3rem;
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="file"],
textarea {
    width: 100%;
    padding: .55rem .7rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}
input:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9rem; }

.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.inline-form { display: inline; }

/* Buttons */
.btn {
    display: inline-block;
    padding: .55rem 1rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font: inherit;
    font-weight: 500;
    text-decoration: none;
    transition: background .15s, border-color .15s;
}
.btn:hover { background: #eef2f7; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn-sm { padding: .35rem .7rem; font-size: .85rem; }
.btn-block { display: block; width: 100%; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .92rem;
}
.table th, .table td {
    padding: .7rem .8rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.table th { color: var(--text-muted); font-weight: 500; background: #f8fafc; }
.table tr:last-child td { border-bottom: none; }

/* Pills */
.pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 500;
    background: #eef2f7;
    color: var(--text);
}
.pill-ok { background: rgba(22, 163, 74, .1); color: var(--ok); }
.pill-danger { background: rgba(220, 38, 38, .1); color: var(--danger); }
.pill-muted { background: #eef2f7; color: var(--text-muted); }

/* Flash */
.flash {
    padding: .7rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    border: 1px solid transparent;
    font-size: .92rem;
}
.flash-success { background: rgba(22, 163, 74, .08); border-color: rgba(22, 163, 74, .25); color: #14532d; }
.flash-error   { background: rgba(220, 38, 38, .08); border-color: rgba(220, 38, 38, .25); color: #7f1d1d; }

/* Mobile toggle */
.nav-toggle {
    display: none;
    position: fixed;
    top: .9rem;
    left: .9rem;
    z-index: 40;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    width: 38px; height: 38px;
    border-radius: 6px;
    font-size: 1.2rem;
    cursor: pointer;
}
.backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, .35);
    z-index: 25;
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.is-open { transform: translateX(0); box-shadow: 0 0 30px rgba(0,0,0,.15); }
    .main { margin-left: 0; }
    .nav-toggle { display: flex; align-items: center; justify-content: center; }
    .backdrop.is-visible { display: block; }
    .topbar { padding-left: 4.2rem; }
    .form-grid { grid-template-columns: 1fr; }
    .content { padding: 1rem; }
}

/* Auth (login page) */
.auth-body {
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow);
}
.auth-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-bottom: 1.5rem;
}
.auth-card h1 { margin-bottom: 1.2rem; }
