:root {
  --gold: #c8960c;
  --gold-light: #e3b23c;
  --gold-dark: #a87c0a;
  --ink: #1a1a1a;
  --charcoal: #262626;
  --cream: #f6f3ec;
  --white: #fff;
  --gray: #6b6b6b;
  --line: #e6e1d6;
  --font: "Poppins", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--cream); color: var(--ink); }
a { color: var(--gold-dark); }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(circle at 30% 20%, #2a2a2a, #141414); }
.login-card { background: var(--white); border-radius: 18px; padding: 40px; width: 100%; max-width: 410px;
  box-shadow: 0 30px 60px rgba(0,0,0,.4); }
.login-brand { text-align: center; margin-bottom: 8px; font-weight: 800; font-size: 1.4rem; letter-spacing: .5px; }
.login-brand .pin { color: var(--gold); }
.login-sub { text-align: center; color: var(--gray); margin-bottom: 26px; font-size: .95rem; }
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 6px; }
.field input { width: 100%; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 10px;
  font-family: inherit; font-size: 1rem; background: #fafafa; }
.field input:focus { outline: none; border-color: var(--gold); background: #fff; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  padding: 13px; border: none; border-radius: 10px; font-weight: 600; font-size: 1rem; cursor: pointer;
  background: var(--gold); color: #fff; transition: background .15s; }
.btn:hover { background: var(--gold-dark); }
.btn[disabled] { opacity: .6; cursor: default; }
.alert { padding: 11px 14px; border-radius: 10px; font-size: .92rem; margin-bottom: 16px; display: none; }
.alert.show { display: block; }
.alert.err { background: #fdecec; color: #b3261e; }
.alert.ok { background: #e7f6ec; color: #1f7a3d; }
.back-link { display:block; text-align:center; margin-top:18px; font-size:.9rem; color:var(--gray); }

/* ---- Dashboard ---- */
.topbar { background: var(--ink); color: #fff; padding: 0 24px; height: 64px; display: flex;
  align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 10; }
.topbar .brand { font-weight: 800; letter-spacing: .5px; }
.topbar .brand .pin { color: var(--gold); }
.topbar .right { display: flex; align-items: center; gap: 16px; font-size: .92rem; }
.topbar .right .who { color: #cfc9bb; }
.topbar button.logout { background: rgba(255,255,255,.1); color: #fff; border: none; padding: 8px 16px;
  border-radius: 8px; cursor: pointer; font-family: inherit; }
.topbar button.logout:hover { background: var(--gold); }

.layout { max-width: 1200px; margin: 0 auto; padding: 28px 24px 60px; }
.tabs { display: flex; gap: 8px; margin-bottom: 24px; flex-wrap: wrap; }
.tab { padding: 10px 20px; border-radius: 999px; background: #fff; border: 1.5px solid var(--line);
  cursor: pointer; font-weight: 600; font-size: .92rem; color: var(--gray); }
.tab.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.panel { display: none; }
.panel.active { display: block; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 26px; }
.kpi { background: #fff; border-radius: 14px; padding: 22px; border: 1px solid var(--line);
  box-shadow: 0 8px 22px rgba(0,0,0,.05); }
.kpi .label { color: var(--gray); font-size: .82rem; text-transform: uppercase; letter-spacing: 1px; font-weight: 600; }
.kpi .value { font-size: 2.1rem; font-weight: 800; margin-top: 6px; }
.kpi .value.gold { color: var(--gold-dark); }

.card { background: #fff; border-radius: 14px; padding: 24px; border: 1px solid var(--line);
  box-shadow: 0 8px 22px rgba(0,0,0,.05); margin-bottom: 22px; }
.card h3 { font-size: 1.1rem; margin-bottom: 16px; display:flex; justify-content:space-between; align-items:center; }
.card h3 select { font-family: inherit; padding: 6px 10px; border-radius: 8px; border: 1.5px solid var(--line); }

.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 22px; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
th { color: var(--gray); font-size: .78rem; text-transform: uppercase; letter-spacing: .5px; }
td .pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .76rem; font-weight: 600;
  background: var(--cream); color: var(--gold-dark); }
.muted { color: var(--gray); font-size: .85rem; }
.truncate { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.toolbar h2 { font-size: 1.4rem; }
.btn-sm { width: auto; padding: 10px 18px; font-size: .92rem; }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: none; place-items: center; z-index: 50; padding: 20px; }
.modal-bg.show { display: grid; }
.modal { background: #fff; border-radius: 16px; padding: 30px; width: 100%; max-width: 460px; }
.modal h3 { margin-bottom: 18px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field select { width: 100%; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 10px; font-family: inherit; font-size: 1rem; background: #fafafa; }
.modal-actions { display: flex; gap: 10px; margin-top: 10px; }
.modal-actions .btn { width: auto; flex: 1; }
.btn-ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn-ghost:hover { background: var(--cream); }
.btn-danger { background: #b3261e; }
.btn-danger:hover { background: #8f1d17; }

.status-dot { display:inline-block; width:8px; height:8px; border-radius:50%; margin-right:6px; }
.status-dot.on { background:#1f7a3d; }
.status-dot.off { background:#b3261e; }
.row-actions button { background:none; border:none; cursor:pointer; color:var(--gray); font-size:.85rem; padding:4px 8px; }
.row-actions button:hover { color: var(--ink); }

@media (max-width: 900px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}
