:root {
    --bg: #f5f6f4;
    --surface: #ffffff;
    --border: #e2e4de;
    --text: #24261f;
    --text-muted: #6b6d63;
    --accent: #0f6e56;
    --accent-light: #e1f5ee;
    --danger: #a32d2d;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, "Segoe UI", "Helvetica Neue", Arial, "Noto Sans Thai", sans-serif;
    line-height: 1.6;
}

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.topbar-inner {
    max-width: 1080px;
    margin: 0 auto;
    padding: 14px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}
.brand { font-weight: 600; color: var(--text); text-decoration: none; font-size: 16px; }
.topbar nav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
}
.topbar nav a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    padding: 4px 0;
}
.topbar nav a:hover { color: var(--accent); }

@media (max-width: 560px) {
    .topbar-inner { padding: 12px 14px; }
    .topbar nav { width: 100%; justify-content: flex-start; gap: 4px 14px; }
    .topbar nav a { font-size: 13px; }
}

.container { max-width: 1080px; margin: 0 auto; padding: 28px 20px 60px; }

h1 { font-size: 22px; font-weight: 600; margin: 0 0 20px; }
h2 { font-size: 18px; font-weight: 600; margin: 0 0 12px; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 720px) {
    .grid-3 { grid-template-columns: 1fr 1fr; }
    .grid-4 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
    .container { padding: 18px 14px 48px; }
    h1 { font-size: 19px; margin-bottom: 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
    h2 { font-size: 16px; }
    .card { padding: 16px; }
    .grid { gap: 12px; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
    .metric .value { font-size: 20px; }
    form { max-width: 100%; }
    button, .btn { width: 100%; text-align: center; }
    form > div[style*="flex"] { flex-direction: column; }
    .chart-wrap { height: 180px; }
}

@media (max-width: 400px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

.profile-card {
    display: block;
    text-decoration: none;
    color: inherit;
}
.profile-card:hover { border-color: var(--accent); }
.profile-card .name { font-weight: 600; font-size: 16px; margin-bottom: 4px; }
.profile-card .meta { font-size: 13px; color: var(--text-muted); }

.metric {
    background: var(--accent-light);
    border-radius: 8px;
    padding: 14px 16px;
}
.metric .label { font-size: 12px; color: var(--accent); font-weight: 500; text-transform: uppercase; letter-spacing: .02em; }
.metric .value { font-size: 24px; font-weight: 600; margin-top: 4px; }
.metric .unit { font-size: 13px; color: var(--text-muted); font-weight: 400; }

form { display: flex; flex-direction: column; gap: 14px; max-width: 420px; }
label { font-size: 13px; font-weight: 500; color: var(--text-muted); display: block; margin-bottom: 4px; }
input[type=text], input[type=password], input[type=date], select, textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
}
textarea { min-height: 70px; resize: vertical; }

button, .btn {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    width: fit-content;
}
button:hover, .btn:hover { opacity: 0.9; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }

.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.alert-error { background: #fcebeb; color: var(--danger); }
.alert-success { background: var(--accent-light); color: var(--accent); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.api-key-box {
    background: #fdf6e3;
    border: 1px solid #f0d998;
    border-radius: 8px;
    padding: 12px 14px;
    font-family: monospace;
    font-size: 14px;
    word-break: break-all;
}

.text-muted { color: var(--text-muted); font-size: 13px; }
.chart-wrap { height: 220px; }
