:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --border: #d9dee5;
  --text: #1c2733;
  --muted: #6b7684;
  --primary: #007bff;
  --primary-dark: #0063cc;
  --secondary: #0d6efd;
  --green-bg: #e2efda; --green-txt: #375623;
  --yellow-bg: #fff2cc; --yellow-txt: #7f6000;
  --red-bg: #fce4d6; --red-txt: #843c0c;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: #b00020; background: #fdecea; padding: 8px 10px; border-radius: 6px; margin: 8px 0; }
.warn { color: var(--yellow-txt); background: var(--yellow-bg); padding: 8px 10px; border-radius: 6px; margin: 6px 0; }

h1, h2, h3 { margin: 0 0 12px; }
h2 { font-size: 22px; }
h3 { font-size: 16px; }

button { cursor: pointer; }
a { color: var(--primary); }

.btn {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 14px;
  background: #e9edf2;
  color: var(--text);
}
.btn:hover { filter: brightness(0.96); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-block { width: 100%; }
.btn-sm { padding: 4px 10px; font-size: 13px; }

/* ── Auth ───────────────────────────────────────────────────────────── */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #14283c 0%, #1f3864 100%);
}
.auth-card {
  background: var(--card);
  padding: 36px 32px;
  border-radius: 12px;
  width: 360px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}
.auth-card h1 { color: #1f3864; font-size: 26px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }

/* ── App layout ──────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: #14283c;
  color: #fff;
}
.app-title { font-weight: 700; font-size: 18px; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tab {
  background: transparent; color: #c7d2de; border: none;
  padding: 8px 14px; border-radius: 6px; font-size: 14px;
}
.tab.active { background: rgba(255,255,255,0.15); color: #fff; }
.app-user { display: flex; align-items: center; gap: 10px; }
.app-user .muted { color: #c7d2de; }
.app-header .btn-ghost { color: #fff; border-color: rgba(255,255,255,0.3); }

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

.card, fieldset.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}
fieldset.card legend { font-weight: 600; padding: 0 6px; }

.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 720px) { .grid.two { grid-template-columns: 1fr; } }

label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #34404d; }
input, select, textarea {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd7f7; border-color: var(--primary); }

.sensor-heading { display: flex; align-items: center; justify-content: space-between; margin: 8px 0 12px; }
.sensor-card { border-left: 4px solid var(--secondary); }
.sensor-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sensor-card-head h4 { margin: 0; }

.file-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.file-meta { font-size: 12px; color: var(--muted); }

.schedule-table { width: 100%; border-collapse: collapse; margin: 8px 0 12px; }
.schedule-table th, .schedule-table td { padding: 4px 6px; text-align: left; font-size: 13px; }
.schedule-table th { color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--border); }
.schedule-table input[type="time"] { padding: 5px 6px; width: 100%; }

.actions { display: flex; align-items: center; gap: 14px; margin: 18px 0; }

/* ── Results ────────────────────────────────────────────────────────── */
.result-status { display: inline-block; padding: 2px 10px; border-radius: 12px; font-weight: 600; font-size: 13px; }
.rs-green { background: var(--green-bg); color: var(--green-txt); }
.rs-yellow { background: var(--yellow-bg); color: var(--yellow-txt); }
.rs-red { background: var(--red-bg); color: var(--red-txt); }

table.data { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table.data th, table.data td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
table.data th { background: #f0f2f5; font-size: 13px; }
table.data tr:last-child td { border-bottom: none; }

.plot { width: 100%; border: 1px solid var(--border); border-radius: var(--radius); margin: 10px 0; }

.report-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.report-card .meta { color: var(--muted); font-size: 13px; }

/* ── Modal ──────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-card { background: #fff; border-radius: 12px; padding: 24px; width: 620px; max-width: 92vw; max-height: 90vh; overflow: auto; }
.modal-card .grid { margin-bottom: 12px; }
.modal-card .actions { justify-content: flex-end; margin-bottom: 0; }

/* ── Logo (settings) ─────────────────────────────────────────────────── */
.logo-section { border-top: 1px solid var(--border); margin-top: 14px; padding-top: 14px; }
.logo-preview {
  display: flex; align-items: center; justify-content: center;
  min-height: 64px; margin-bottom: 10px;
  border: 1px dashed var(--border); border-radius: 8px; background: #fafbfc;
}
.logo-preview img { max-height: 90px; max-width: 260px; object-fit: contain; padding: 8px; }
.logo-controls { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.logo-controls input[type="file"] { border: none; padding: 4px 0; }
