:root {
    --sdw-bg: #f4f6f9;
    --sdw-surface: #ffffff;
    --sdw-sidebar: #0f172a;
    --sdw-sidebar-muted: #94a3b8;
    --sdw-accent: #2563eb;
    --sdw-border: #e2e8f0;
    --sdw-radius: 14px;
}

* { box-sizing: border-box; }

body.sdw-body {
    margin: 0;
    background: var(--sdw-bg);
    color: #0f172a;
    font-family: "Segoe UI", "Inter", system-ui, -apple-system, sans-serif;
    font-size: 14.5px;
}

.sdw-shell {
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    min-height: 100vh;
}

/* ------------------------------------------------------------------ sidebar */
.sdw-sidebar {
    background: var(--sdw-sidebar);
    color: #e2e8f0;
    padding: 22px 18px;
    display: flex;
    flex-direction: column;
    gap: 22px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sdw-brand {
    display: flex;
    gap: 12px;
    align-items: center;
    color: #fff;
    text-decoration: none;
}

.sdw-brand small {
    display: block;
    color: var(--sdw-sidebar-muted);
    font-size: 11.5px;
    line-height: 1.2;
}

.sdw-brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    color: #fff;
    flex: 0 0 auto;
}

.sdw-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.sdw-nav-link {
    color: #cbd5e1;
    text-decoration: none;
    padding: 9px 12px;
    border-radius: 9px;
    font-weight: 500;
    font-size: 13.6px;
}

.sdw-nav-link:hover {
    background: rgba(148, 163, 184, .14);
    color: #fff;
}

.sdw-nav-link.active {
    background: var(--sdw-accent);
    color: #fff;
}

.sdw-sidebar-footer { border-top: 1px solid rgba(148, 163, 184, .22); padding-top: 14px; }

.sdw-user { display: flex; gap: 10px; align-items: center; }

.sdw-user strong { display: block; font-size: 13px; color: #fff; }
.sdw-user small { color: var(--sdw-sidebar-muted); font-size: 11.5px; }

.sdw-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(148, 163, 184, .25);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: #fff;
}

/* --------------------------------------------------------------------- main */
.sdw-main { padding: 26px 30px 46px; min-width: 0; }

.sdw-topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    margin-bottom: 20px;
}

.sdw-page-title { font-size: 21px; font-weight: 650; margin: 0; }
.sdw-page-subtitle { margin: 4px 0 0; color: #64748b; font-size: 13px; }

/* -------------------------------------------------------------------- cards */
.sdw-card {
    background: var(--sdw-surface);
    border: 1px solid var(--sdw-border);
    border-radius: var(--sdw-radius);
    padding: 20px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}

.sdw-card + .sdw-card { margin-top: 18px; }

.sdw-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    margin-bottom: 14px;
}

.sdw-card-title { font-size: 15px; font-weight: 640; margin: 0; }

.sdw-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.sdw-stat {
    background: var(--sdw-surface);
    border: 1px solid var(--sdw-border);
    border-radius: var(--sdw-radius);
    padding: 16px 18px;
}

.sdw-stat-label { color: #64748b; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.sdw-stat-value { font-size: 24px; font-weight: 660; margin-top: 6px; }
.sdw-stat-value small { font-size: 13px; color: #64748b; font-weight: 500; }

/* -------------------------------------------------------------------- tables */
.sdw-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.6px; }

.sdw-table th {
    text-align: left;
    color: #64748b;
    font-weight: 600;
    font-size: 11.6px;
    letter-spacing: .04em;
    text-transform: uppercase;
    padding: 9px 12px;
    border-bottom: 1px solid var(--sdw-border);
    white-space: nowrap;
}

.sdw-table td {
    padding: 11px 12px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

.sdw-table tbody tr:hover { background: #f8fafc; }
.sdw-table tbody tr:last-child td { border-bottom: none; }

.sdw-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sdw-mono { font-family: "Cascadia Mono", "Consolas", monospace; font-size: 12.6px; }

.sdw-empty { text-align: center; color: #94a3b8; padding: 26px 0; }

/* --------------------------------------------------------------------- misc */
.sdw-badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    background: #eef2ff;
    color: #3730a3;
    white-space: nowrap;
}

.sdw-badge-success { background: #dcfce7; color: #166534; }
.sdw-badge-warning { background: #fef3c7; color: #92400e; }
.sdw-badge-danger { background: #fee2e2; color: #991b1b; }
.sdw-badge-muted { background: #f1f5f9; color: #475569; }

.sdw-toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 16px;
}

.sdw-pagination { display: flex; gap: 6px; align-items: center; margin-top: 16px; }
.sdw-pagination a, .sdw-pagination span {
    padding: 6px 11px;
    border-radius: 8px;
    border: 1px solid var(--sdw-border);
    color: #334155;
    text-decoration: none;
    background: #fff;
    font-size: 13px;
}
.sdw-pagination .current { background: var(--sdw-accent); border-color: var(--sdw-accent); color: #fff; }

.sdw-form .form-label { font-weight: 600; font-size: 12.6px; color: #334155; }
.sdw-form .form-control, .sdw-form .form-select { font-size: 14px; }

.sdw-image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }

.sdw-image-grid img {
    width: 100%;
    height: 150px;
    object-fit: contain;
    background: #fff;
    border: 1px solid var(--sdw-border);
    border-radius: 10px;
    padding: 6px;
}

.sdw-grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.sdw-grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }

.sdw-lines-table input { min-width: 84px; }
.sdw-lines-table .form-control { font-size: 13.5px; padding: .35rem .5rem; }

.sdw-progress { height: 8px; background: #e2e8f0; border-radius: 999px; overflow: hidden; }
.sdw-progress > span { display: block; height: 100%; background: var(--sdw-accent); }

/* ---------------------------------------------------------------------- auth */
.sdw-auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: radial-gradient(1200px 500px at 50% -10%, #dbeafe 0%, #f4f6f9 55%);
    font-family: "Segoe UI", "Inter", system-ui, sans-serif;
}

.sdw-auth-card {
    width: min(430px, 100%);
    background: #fff;
    border: 1px solid var(--sdw-border);
    border-radius: 18px;
    padding: 28px;
    box-shadow: 0 18px 45px rgba(15, 23, 42, .08);
}

.sdw-auth-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.sdw-auth-brand small { display: block; color: #64748b; font-size: 12px; }
.sdw-auth-footer { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--sdw-border); }

.sdw-error-code { font-size: 52px; font-weight: 700; margin: 6px 0 0; color: #1d4ed8; }
.sdw-error-title { font-size: 17px; font-weight: 600; margin: 6px 0; }

@media (max-width: 860px) {
    .sdw-shell { grid-template-columns: 1fr; }
    .sdw-sidebar { position: static; height: auto; }
    .sdw-main { padding: 18px; }
}

/* ------------------------------------------------ dashboard desktop tiles */
.db-toolbar { display: flex; justify-content: flex-end; gap: 8px; margin-bottom: 12px; }
.db-edit-actions { display: flex; gap: 8px; align-items: center; }

.db-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 16px;
}

.db-tile {
    position: relative;
    min-height: 132px;
    padding: 18px;
    border: 1px solid var(--sdw-border, #e5e7eb);
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.db-tile:hover { transform: translateY(-2px); box-shadow: 0 12px 24px rgba(15, 23, 42, 0.08); }
.db-tile-list { grid-column: span 2; min-height: 200px; }
.db-tile-kpi { background: linear-gradient(160deg, #ffffff 0%, #f7f9ff 100%); }
.db-tile-kpi:nth-child(4n+1) { background: linear-gradient(160deg, #eef4ff 0%, #ffffff 70%); }
.db-tile-kpi:nth-child(4n+2) { background: linear-gradient(160deg, #eefaf3 0%, #ffffff 70%); }
.db-tile-kpi:nth-child(4n+3) { background: linear-gradient(160deg, #fff6ea 0%, #ffffff 70%); }
.db-tile-kpi:nth-child(4n+4) { background: linear-gradient(160deg, #f7efff 0%, #ffffff 70%); }

.db-tile-link { position: absolute; inset: 0; border-radius: 16px; }
.db-kpi-icon { font-size: 20px; opacity: 0.75; }
.db-kpi-label { margin-top: 6px; color: #4b5563; font-size: 13px; font-weight: 600; letter-spacing: 0.01em; }
.db-kpi-value { margin-top: 6px; font-size: 26px; font-weight: 700; color: #0f172a; line-height: 1.15; }
.db-kpi-sub { margin-top: 4px; color: #6b7280; font-size: 12px; }

.db-tile-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.db-tile-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.db-tile-head a { font-size: 12px; color: #2563eb; text-decoration: none; }
.db-list { list-style: none; margin: 0; padding: 0; }
.db-list li + li { border-top: 1px solid #f1f5f9; }
.db-list a { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 8px 0; text-decoration: none; color: inherit; }
.db-list-label { font-size: 13px; font-weight: 600; color: #0f172a; }
.db-list-sub { grid-column: 1; font-size: 12px; color: #6b7280; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db-list-value { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-size: 13px; font-weight: 600; color: #111827; }

.db-shortcut { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; height: 100%; text-decoration: none; color: #0f172a; }
.db-shortcut-icon { display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 12px; background: #eef4ff; font-size: 20px; }
.db-shortcut-label { font-size: 13px; font-weight: 600; text-align: center; }

.db-tile-handle, .db-tile-remove, .db-tile-move { display: none; }
.db-editing .db-tile { border-style: dashed; cursor: grab; }
.db-editing .db-tile-handle { display: block; position: absolute; top: 6px; left: 10px; color: #94a3b8; font-size: 15px; }
.db-editing .db-tile-remove { display: block; position: absolute; top: 6px; right: 8px; border: 0; background: #fee2e2; color: #b91c1c; width: 24px; height: 24px; border-radius: 50%; line-height: 1; font-size: 15px; cursor: pointer; }
.db-editing .db-tile-move { display: flex; position: absolute; bottom: 8px; right: 8px; gap: 4px; }
.db-editing .db-tile-move button { border: 1px solid #e5e7eb; background: #fff; border-radius: 8px; width: 26px; height: 26px; cursor: pointer; color: #374151; }
.db-editing .db-tile-link { pointer-events: none; }
.db-tile.is-dragging { opacity: 0.55; transform: scale(0.98); }
.db-tile.is-new { animation: db-pop 0.25s ease; }
@keyframes db-pop { from { transform: scale(0.94); opacity: 0.4; } to { transform: scale(1); opacity: 1; } }

.db-cat-heading { margin: 14px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: #6b7280; }
.db-cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.db-cat-item { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid #e5e7eb; border-radius: 10px; background: #fff; cursor: pointer; font-size: 13px; text-align: left; }
.db-cat-item:hover { border-color: #2563eb; background: #eff6ff; }
.db-cat-icon { font-size: 16px; }

@media (max-width: 760px) {
    .db-grid { grid-template-columns: 1fr; }
    .db-tile-list { grid-column: span 1; }
    .db-kpi-value { font-size: 22px; }
}
/* Sidebar preferences: language + learning mode, above the user block */
.sdw-sidebar-prefs {
    margin-top: auto;
    display: grid;
    gap: 8px;
    padding: 12px 2px 10px;
    border-top: 1px solid rgba(148, 163, 184, .22);
}
.sdw-pref-form { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sdw-pref-form label { margin: 0; font-size: 12px; font-weight: 600; color: var(--sdw-sidebar-muted); }
.sdw-pref-form .form-select { width: 96px; height: 36px; padding: 0 8px; border-radius: 10px; border-color: rgba(148, 163, 184, .35); background-color: #1e293b; color: #e2e8f0; }
.sdw-switch { position: relative; width: 44px; height: 26px; border: 0; border-radius: 999px; background: #334155; cursor: pointer; transition: background .18s ease; }
.sdw-switch.is-on { background: #2563eb; }
.sdw-switch-knob { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .18s ease; }
.sdw-switch.is-on .sdw-switch-knob { transform: translateX(18px); }
.sdw-sidebar-footer { border-top: 1px solid rgba(148, 163, 184, .22); padding-top: 12px; }

@media (max-width: 860px) {
    .sdw-sidebar-prefs { padding-bottom: 6px; }
    .sdw-pref-form { min-height: 44px; }
    .sdw-pref-form .form-select { height: 44px; font-size: 16px; }
    .sdw-switch { width: 52px; height: 30px; }
    .sdw-switch-knob { width: 24px; height: 24px; }
    .sdw-switch.is-on .sdw-switch-knob { transform: translateX(22px); }
}
/* Clicking the user opens personal settings */
a.sdw-user { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; padding: 6px 4px; border-radius: 10px; }
a.sdw-user:hover { background: rgba(148, 163, 184, .12); }
a.sdw-user > div { min-width: 0; }
.sdw-user-caret { margin-left: auto; color: var(--sdw-sidebar-muted); font-size: 18px; line-height: 1; }