:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --border: #dfe3e8;
    --text: #1f2933;
    --muted: #6b7785;
    --primary: #2b6cb0;
    --primary-dark: #1e4e7f;
    --danger: #c0392b;
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar h1 { font-size: 1.25rem; margin: 0; }

main { padding: 24px; max-width: 1400px; margin: 0 auto; }

.toolbar {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 0.8rem; color: var(--muted); }
.field-actions { flex-direction: row; gap: 8px; margin-left: auto; }

input, select, textarea {
    font: inherit;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
}

.btn {
    padding: 8px 16px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); text-decoration: none; }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; }

.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: auto;
}

table { width: 100%; border-collapse: collapse; }
th, td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    white-space: nowrap;
}
th.num, td.num { text-align: right; }
thead th { background: #f8fafc; color: var(--muted); font-weight: 600; position: sticky; top: 0; }
tbody tr[data-clickable] { cursor: pointer; }
tbody tr[data-clickable]:hover { background: #f1f5f9; }
.empty { text-align: center; color: var(--muted); padding: 24px !important; }

.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    z-index: 50;
}
.modal-overlay.hidden { display: none; }

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    width: 100%;
    max-width: 720px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-sm { max-width: 420px; }

.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 1.1rem; }
.modal-close {
    border: none; background: none; font-size: 1.4rem; cursor: pointer; color: var(--muted);
    line-height: 1;
}
.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal-body h3 { margin: 20px 0 8px; font-size: 0.95rem; }

.group-info {
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
}
.group-info b { color: var(--text); }

.item-form .grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 10px;
}
.item-form .field { margin-bottom: 10px; }
.item-form textarea { resize: vertical; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-actions button {
    border: none; background: none; cursor: pointer; font-size: 0.85rem;
    color: var(--primary);
}
.row-actions button.delete { color: var(--danger); }

.alert { padding: 10px 12px; border-radius: var(--radius); font-size: 0.85rem; margin-bottom: 12px; }
.alert-error { background: #fdecea; color: var(--danger); border: 1px solid #f5c6c1; }

.toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    background: #1f2933; color: #fff; padding: 10px 18px; border-radius: var(--radius);
    font-size: 0.9rem; z-index: 100;
}
.toast.error { background: var(--danger); }
.toast.hidden { display: none; }

/* Login page */
.login-body {
    display: flex; align-items: center; justify-content: center; min-height: 100vh;
}
.login-box {
    background: var(--surface);
    padding: 32px 28px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    width: 100%;
    max-width: 340px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.login-box h1 { margin: 0; font-size: 1.3rem; }
.login-box .subtitle { margin: 0 0 8px; color: var(--muted); font-size: 0.85rem; }
