/* =========================================================
   base.css  -  colours, reset, buttons, forms, cards, badges,
   tables, modal and toast. Used by every page.
   ========================================================= */
:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-50: #eff6ff;
  --blue-100: #dbeafe;
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;

  --green: #16a34a;
  --green-bg: #dcfce7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --amber: #d97706;
  --amber-bg: #fef3c7;
  --gray-bg: #f1f5f9;

  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 2px 10px rgba(15, 23, 42, 0.05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans JP", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
body.modal-open { overflow: hidden; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
p { margin: 0 0 .6em; }
a { color: var(--blue); }
img { max-width: 100%; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* Hide the page until we know the user is allowed to see it */
body.booting .app-header, body.booting .app-main { visibility: hidden; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: #fff; color: var(--text); font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--gray-bg); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--blue); }
.btn-ghost:hover { background: var(--blue-50); }
.btn-sm { padding: 5px 11px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.icon-btn {
  border: 0; background: transparent; font-size: 24px; line-height: 1; cursor: pointer;
  color: var(--muted); padding: 2px 8px; border-radius: 8px;
}
.icon-btn:hover { background: var(--gray-bg); color: var(--text); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label, .label { font-size: 13px; font-weight: 600; color: #334155; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=time],
input[type=url], input[type=search], input[type=number], select, textarea {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--text);
  border: 1px solid #cbd5e1; border-radius: 10px; background: #fff;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
input:disabled, select:disabled { background: var(--gray-bg); color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-error {
  color: var(--red); background: var(--red-bg); border-radius: 10px;
  padding: 9px 12px; font-size: 14px; margin-bottom: 12px;
}
.form-error:empty { display: none; }
.hint { font-size: 12.5px; color: var(--muted); }

.file-drop {
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 22px 14px; border: 2px dashed #cbd5e1; border-radius: 12px; color: var(--muted);
  cursor: pointer; flex-direction: column; gap: 8px;
}
.file-drop:hover { border-color: var(--blue); background: var(--blue-50); }
.file-drop input { max-width: 100%; }

/* ---------- Cards ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid #eef2f7; padding: 20px;
}
.card h3 { font-size: 16px; margin-bottom: 4px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 700; white-space: nowrap;
}
.badge-green { background: var(--green-bg); color: #166534; }
.badge-red { background: var(--red-bg); color: #991b1b; }
.badge-amber { background: var(--amber-bg); color: #92400e; }
.badge-blue { background: var(--blue-100); color: #1e40af; }
.badge-gray { background: var(--gray-bg); color: #475569; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: 12px; }
table.table { width: 100%; border-collapse: collapse; min-width: 560px; }
.table th {
  text-align: left; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 700; padding: 10px 14px; background: #f8fafc;
  border-bottom: 1px solid var(--border);
}
.table td { padding: 12px 14px; border-bottom: 1px solid #eef2f7; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafcff; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Misc ---------- */
.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.loading { text-align: center; color: var(--muted); padding: 60px 12px; }
.notice {
  background: var(--amber-bg); color: #92400e; border-radius: 12px;
  padding: 12px 16px; margin-bottom: 16px; font-size: 14px;
}
.demo-banner {
  background: #1e293b; color: #e2e8f0; text-align: center; font-size: 13px; padding: 6px 12px;
}
.demo-banner a { color: #93c5fd; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: fade .15s ease;
}
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 480px; max-height: 92vh;
  display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(15, 23, 42, .3);
}
.modal.wide { max-width: 720px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 18px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.detail-list { display: grid; grid-template-columns: 130px 1fr; gap: 10px 14px; margin: 0; }
.detail-list dt { color: var(--muted); font-size: 13.5px; }
.detail-list dd { margin: 0; font-weight: 500; word-break: break-word; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Toasts ---------- */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: #0f172a; color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: var(--shadow); max-width: 340px; transition: opacity .3s, transform .3s;
}
.toast.success { background: #15803d; }
.toast.error { background: #b91c1c; }
.toast.hide { opacity: 0; transform: translateY(6px); }

@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }
  .detail-list { grid-template-columns: 1fr; gap: 2px 0; }
  .detail-list dd { margin-bottom: 8px; }
}
