* { box-sizing: border-box; }
:root {
  --bg: #f8fafc;
  --fg: #0f172a;
  --muted: #64748b;
  --brand: #5f8530;
  --brand-dark: #4a6826;
  --brand-light: #f3f8eb;
  --border: #e2e8f0;
  --card: #ffffff;
  --ok: #5f8530;
  --err: #b91c1c;
}
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--fg); }
[hidden] { display: none !important; }

header#topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 2rem; background: var(--card); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 600; color: var(--fg); font-size: 1.1rem; text-decoration: none; }
.brand .logo-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; border-radius: .375rem;
  background: var(--brand); color: white; font-weight: 700; font-size: .95rem;
}
.brand .sep { color: var(--muted); margin: 0 .25rem; font-weight: 400; }
.brand .kanzlei { color: var(--muted); font-weight: 500; }
.meta { display: flex; gap: 1rem; align-items: center; color: var(--muted); }
button.link { background: none; border: none; color: var(--brand); cursor: pointer; text-decoration: underline; padding: 0; }
button.link:hover { color: var(--brand-dark); }

main { max-width: 1100px; margin: 2rem auto; padding: 0 1.5rem; }
main.card {
  max-width: 460px; margin-top: 6rem; padding: 2.25rem; background: var(--card);
  border-radius: 12px; box-shadow: 0 4px 24px rgba(15,23,42,0.08);
  border: 1px solid var(--border);
}
main.card .brand-header {
  display: flex; flex-direction: column; align-items: center; gap: .65rem; margin-bottom: 1.5rem;
}
main.card .brand-header .logo-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 3rem; height: 3rem; border-radius: .5rem;
  background: var(--brand); color: white; font-weight: 700; font-size: 1.4rem;
  box-shadow: 0 2px 8px rgba(95,133,48,0.25);
}
main.card .brand-header .wordmark { font-weight: 600; font-size: 1.15rem; }
main.card h1 { font-size: 1.5rem; text-align: center; margin: 0 0 .25rem; }
main.card > p.muted { text-align: center; }
h1, h2, h3 { color: var(--fg); margin-top: 0; }
p.muted, small.hint, .muted { color: var(--muted); font-size: 0.9rem; }

form#login-form { display: flex; flex-direction: column; gap: .5rem; margin-top: 1.25rem; }
input, select, button, textarea {
  font: inherit; padding: .55rem .75rem; border: 1px solid var(--border); border-radius: 6px; background: var(--card); color: var(--fg);
}
button { background: var(--brand); color: white; cursor: pointer; border-color: var(--brand); transition: background .15s; }
button:hover { background: var(--brand-dark); }

nav.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.5rem; }
nav.tabs .tab {
  background: transparent; color: var(--muted); border: none; padding: .75rem 1.25rem;
  border-bottom: 2px solid transparent; border-radius: 0; cursor: pointer; font-weight: 500;
}
nav.tabs .tab:hover { color: var(--fg); }
nav.tabs .tab.active { color: var(--brand); border-bottom-color: var(--brand); }

section.tab-pane { display: none; background: var(--card); padding: 1.5rem 2rem; border-radius: 12px; box-shadow: 0 1px 8px rgba(20,30,60,0.05); }
section.tab-pane.active { display: block; }

form.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem 1.5rem; margin-top: 1rem; }
form.grid label { display: flex; flex-direction: column; gap: .35rem; }
form.grid label span { font-weight: 500; }
form.grid .section-title { grid-column: 1 / -1; margin: 1rem 0 0; padding-bottom: .35rem; border-bottom: 1px solid var(--border); font-size: 1.05rem; color: var(--brand); }
form.grid .actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 1rem; }

table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
th, td { text-align: left; padding: .65rem .5rem; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--muted); font-size: .9rem; }
td button { padding: .3rem .65rem; font-size: .85rem; }
td.badge { color: white; padding: 2px 8px; border-radius: 10px; font-size: .75rem; }
.badge-ok  { background: var(--brand); color: white; padding: 2px 8px; border-radius: 10px; font-size: .75rem; }
.badge-off { background: var(--muted); color: white; padding: 2px 8px; border-radius: 10px; font-size: .75rem; }

.status { font-size: .9rem; }
.status.ok { color: var(--ok); }
.status.err { color: var(--err); }

/* Dashboard cards */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1.25rem; }
.dash-grid .card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 1.25rem 1.5rem;
}
.dash-grid .card h3 { margin: 0 0 .75rem; font-size: 1rem; color: var(--brand-dark); }
.stats-row { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.stats-row > div { flex: 1; min-width: 5rem; }
.stat-num { font-size: 1.75rem; font-weight: 600; color: var(--brand-dark); line-height: 1; }
.stat-label { font-size: .8rem; color: var(--muted); margin-top: .25rem; }

.dash-grid .card.card-wide { grid-column: 1 / -1; }
.dash-grid .card .hint { font-size: .85rem; margin: 0 0 1rem; }

.heatmap { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; align-items: end; height: 80px; }
.heatmap > div { background: var(--brand); border-radius: 2px 2px 0 0; min-height: 4px; }
.heatmap > div[title]:hover { background: var(--brand-dark); }

.day-chart { display: flex; align-items: end; gap: .35rem; height: 90px; }
.day-chart .day {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: end; height: 100%;
}
.day-chart .day .bar { background: var(--brand); width: 100%; border-radius: 3px 3px 0 0; min-height: 3px; }
.day-chart .day .bar:hover { background: var(--brand-dark); }
.day-chart .day .lbl { font-size: .7rem; color: var(--muted); margin-top: .25rem; white-space: nowrap; }

.outcome-table { width: 100%; }
.outcome-table td { padding: .35rem .5rem; border-bottom: 1px solid var(--border); }
.outcome-table td:nth-child(2), .outcome-table td:nth-child(3) { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.outcome-table td.muted { font-weight: normal; }

.tarif-cell { font-weight: 500; text-transform: capitalize; }
.tarif-cell.no-tarif { color: var(--muted); font-style: italic; font-weight: normal; }
.usage-cell { font-variant-numeric: tabular-nums; }
.usage-cell.over { color: var(--err); font-weight: 600; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,0.45); display: flex; align-items: center; justify-content: center; padding: 1.5rem; z-index: 100; }
.modal-card { background: var(--card); border-radius: 12px; max-width: 720px; width: 100%; max-height: 90vh; overflow: auto; padding: 2rem; position: relative; }
.modal-card.modal-wide { max-width: 960px; }
.modal-card .close { position: absolute; top: .5rem; right: .75rem; background: none; border: none; color: var(--muted); font-size: 1.5rem; cursor: pointer; padding: 0 .5rem; }
.modal-card .close:hover { color: var(--fg); }
.modal-card h2 { margin: 0 0 .5rem; }

/* Detail-Modal-Sub-Sections */
.detail-section { margin-top: 1.5rem; }
.detail-section h3 { font-size: 1rem; color: var(--brand-dark); margin: 0 0 .5rem; border-bottom: 1px solid var(--border); padding-bottom: .35rem; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-top: .5rem; }
.detail-grid .stat-num { font-size: 1.4rem; }
.trend-up   { color: var(--brand); }
.trend-down { color: var(--err); }
.trend-neutral { color: var(--muted); }

.note-feed { max-height: 240px; overflow: auto; }
.note-item { padding: .5rem .75rem; border-left: 3px solid var(--brand); background: var(--brand-light); margin-bottom: .5rem; border-radius: 0 4px 4px 0; }
.note-item .note-meta { font-size: .75rem; color: var(--muted); margin-bottom: .25rem; }
.note-item .note-delete { float: right; background: none; border: none; color: var(--err); cursor: pointer; font-size: .85rem; padding: 0; }

.health-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.health-card { padding: .75rem 1rem; background: var(--brand-light); border-radius: 6px; }
.health-card.bad { background: #fef2f2; }
.health-card .health-label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.health-card .health-value { font-size: 1.1rem; font-weight: 600; margin-top: .25rem; }

.health-line { display: flex; justify-content: space-between; align-items: center; padding: .35rem 0; }
.health-line .dot { width: .65rem; height: .65rem; border-radius: 50%; display: inline-block; margin-right: .5rem; }
.health-line .dot.ok  { background: var(--brand); }
.health-line .dot.bad { background: var(--err); }
.health-line .dot.off { background: var(--muted); }

.recent-feed-row td { font-size: .85rem; }

.outcome-table th { font-weight: 600; color: var(--muted); font-size: .85rem; text-align: left; padding: .35rem .5rem; border-bottom: 1px solid var(--border); }
.outcome-table td.right { text-align: right; }
