:root {
    --primary: #4f46e5;
    --primary-dark: #3730a3;
    --bg: #f5f7fb;
    --text: #1f2937;
    --border: #e5e7eb;
    --danger: #dc2626;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
}

h1 span, .bar strong span { color: var(--primary); }

.bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    background: #fff;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.bar .who { margin-left: auto; font-size: 0.9rem; opacity: 0.7; }

.layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

nav#tables {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    align-self: start;
    padding: 0.75rem;
    border-radius: 1rem;
    background: #fff;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

nav#tables button {
    padding: 0.6rem 0.9rem;
    border: 0;
    border-radius: 0.6rem;
    font: inherit;
    text-align: left;
    color: var(--text);
    background: transparent;
    cursor: pointer;
}

nav#tables button:hover { background: var(--bg); }
nav#tables button.active { color: #fff; background: var(--primary); font-weight: 600; }

main { min-width: 0; }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.toolbar h2 { margin: 0; margin-right: auto; }

input, select, textarea {
    width: 100%;
    padding: 0.6rem 0.9rem;
    border: 2px solid var(--border);
    border-radius: 0.7rem;
    font: inherit;
    color: var(--text);
    background: #fff;
}

.toolbar input { width: 260px; }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.18);
}

.invalid { border-color: var(--danger); }

.btn {
    display: inline-block;
    padding: 0.55rem 1.2rem;
    border: 2px solid var(--primary);
    border-radius: 999px;
    font: inherit;
    font-weight: 600;
    color: var(--primary);
    background: #fff;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.btn:hover { color: #fff; background: var(--primary); }
.btn.primary { color: #fff; background: var(--primary); }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.small { padding: 0.25rem 0.8rem; font-size: 0.85rem; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { color: #fff; background: var(--danger); }
.btn.link { border: 0; background: none; color: var(--primary); font-weight: 500; text-decoration: underline; }
.btn.link:hover { color: var(--primary-dark); background: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.auth-error, .notice {
    margin: 0 0 1rem;
    padding: 0.6rem 1rem;
    border-radius: 0.8rem;
    font-size: 0.9rem;
}

.auth-error { color: #b91c1c; background: #fee2e2; }
.notice { color: #166534; background: #dcfce7; }

.editor-card {
    margin-bottom: 1.5rem;
    padding: 1.25rem;
    border-radius: 1rem;
    background: #fff;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.editor-card h3 { margin-top: 0; }

.fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
}

.field label { display: block; margin-bottom: 0.3rem; font-size: 0.85rem; font-weight: 600; }
.form-actions { display: flex; gap: 0.75rem; margin-top: 1.25rem; }

.table-wrap {
    overflow-x: auto;
    border-radius: 1rem;
    background: #fff;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { padding: 0.65rem 0.9rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
tbody tr:hover, tbody tr:hover td.actions { background: #f9fafb; }
td.actions, th:last-child { position: sticky; right: 0; background: #fff; box-shadow: -6px 0 8px -6px rgba(0, 0, 0, 0.12); }
td.actions .btn + .btn { margin-left: 0.4rem; }
th .sort { padding: 0; border: 0; font: inherit; font-weight: 700; color: inherit; background: none; cursor: pointer; }
.count, .empty { font-size: 0.9rem; opacity: 0.75; }

.pager { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem; margin-top: 1.25rem; }
.pager .page {
    min-width: 2.3rem;
    padding: 0.35rem 0.8rem;
    border: 2px solid var(--primary);
    border-radius: 999px;
    font: inherit;
    font-weight: 600;
    color: var(--primary);
    background: #fff;
    cursor: pointer;
}
.pager .page:hover:not(:disabled), .pager .page.current { color: #fff; background: var(--primary); }
.pager .page:disabled { opacity: 0.4; cursor: not-allowed; }

.login-page { display: grid; place-items: center; padding: 1.5rem; }

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 2rem;
    border-radius: 1.25rem;
    background: #fff;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1);
}

.login-card h1 { margin: 0 0 0.5rem; font-size: 1.8rem; }
.login-card .lead { margin: 0 0 1.5rem; opacity: 0.75; }
.login-card label { display: block; margin-bottom: 0.3rem; font-weight: 600; }
.login-card form { display: flex; flex-direction: column; gap: 0.9rem; }
.login-card #code { font-size: 1.6rem; letter-spacing: 0.4em; text-align: center; }
.login-card #message { margin: 1rem 0 0; }

@media (max-width: 800px) {
    .layout { grid-template-columns: 1fr; padding: 1rem; }
    nav#tables { flex-direction: row; flex-wrap: wrap; }
    .toolbar input { width: 100%; }
}
