:root {
  color-scheme: dark; /* keeps any remaining UA widget (date picker, scrollbar) dark */
  --bg: #0e1117;
  --card: #161b22;
  --card-2: #1c2230;
  --border: #232a36;
  --border-hi: #33405a;
  --float: #0b0f16;
  --text: #e6edf3;
  --muted: #7d8590;
  --green: #2ecc8f;
  --green-dim: #1f9d6f;
  --red: #f57b7b;
  --orange: #e3a008;
  --gray: #2b3340;
  --blue: #4d9fff;
  --shadow: 0 14px 38px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

/* Chrome/Safari keep a UA-blue focus ring otherwise */
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

::selection { background: rgba(46, 204, 143, .28); color: var(--text); }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: #2f3947 transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #2f3947; border-radius: 6px; border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: #3d4a5c; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif;
  line-height: 1.5;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.page { max-width: 820px; margin: 0 auto; padding: 32px 20px 64px; }
.page-narrow { max-width: 640px; }
.subtle { color: var(--muted); }
.small { font-size: 12px; }

/* Hero */
.hero { text-align: center; padding: 24px 0 28px; }
.hero-compact { padding: 8px 0 20px; }
.hero h1 { font-size: 32px; font-weight: 700; margin: 16px 0 8px; }
.hero-icon {
  width: 52px; height: 52px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 700; color: #fff;
}
.hero-ok { background: var(--green); }
.hero-minor { background: var(--orange); }
.hero-major { background: var(--red); }

/* Card */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px 24px;
  margin-bottom: 18px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.card-head h2 { font-size: 15px; font-weight: 600; margin: 0; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 20px;
  background: var(--card-2);
}
.pill-ok { color: var(--green); }
.pill-ok::before { content: "\2713"; color: var(--green); }
.pill-minor, .pill-major { color: var(--orange); }

/* Service rows */
.service { padding: 16px 0; border-top: 1px solid var(--border); }
.service:first-of-type { border-top: none; }
.service-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.service-name { font-weight: 600; }
.uptime { margin-left: auto; color: var(--green); font-size: 13px; }
.uptime.subtle { color: var(--muted); }

.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-up { background: var(--green); }
.dot-down { background: var(--red); }
.dot-unknown { background: var(--muted); }

/* Uptime bars */
.bars { display: flex; gap: 2px; height: 34px; align-items: stretch; }
.bar {
  flex: 1; min-width: 2px; border-radius: 2px; background: var(--gray);
  transition: filter .12s ease, transform .12s ease;
}
.bar-up { background: var(--green); }
.bar-down { background: var(--red); }
.bar-partial { background: var(--orange); }
.bar-none { background: var(--gray); }
.bar:hover, .bar.is-tipped { filter: brightness(1.3); transform: scaleY(1.08); }
.bar:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
.bars-legend { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 6px; }

/* Notices on status page */
.notices { padding: 8px 12px; }
.notice {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  border-radius: 8px; color: var(--text);
}
.notice:hover { background: var(--card-2); text-decoration: none; }
.notice-title { flex: 1; font-weight: 500; }
.notice-tag {
  font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 5px;
  background: var(--card-2); color: var(--muted); white-space: nowrap;
}
.tag-incident { background: rgba(245,123,123,.15); color: var(--red); }
.tag-maintenance { background: rgba(77,159,255,.15); color: var(--blue); }

.badge {
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 12px;
  background: var(--card-2); color: var(--muted); white-space: nowrap;
}
.badge-investigating, .badge-identified { color: var(--orange); background: rgba(227,160,8,.15); }
.badge-monitoring, .badge-in_progress, .badge-scheduled { color: var(--blue); background: rgba(77,159,255,.15); }
.badge-resolved, .badge-completed { color: var(--green); background: rgba(46,204,143,.15); }

/* History list */
.history-list { list-style: none; padding: 0; margin: 0; }
.history-list li {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 0; border-top: 1px solid var(--border);
}
.history-list li:first-child { border-top: none; }

/* Timeline */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 14px 0; border-top: 1px solid var(--border); }
.timeline li:first-child { border-top: none; }
.timeline-body { margin: 8px 0 4px; white-space: pre-wrap; }

/* Forms / admin */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 14px; }
.row label { flex: 1; }
input, select, textarea {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: 9px 11px; font-size: 14px; font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(77, 159, 255, .18);
}
input::placeholder, textarea::placeholder { color: #5b6473; }
textarea { resize: vertical; }

/* Autofill otherwise repaints the field in the UA's light yellow */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--bg) inset;
  caret-color: var(--text);
}

/* The calendar popup stays native (color-scheme keeps it dark); recolor its trigger */
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(58%) sepia(10%) saturate(400%) hue-rotate(178deg);
  cursor: pointer; opacity: .85;
}
input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover { opacity: 1; }

.btn {
  display: inline-block; cursor: pointer; border: 1px solid var(--border);
  background: var(--card-2); color: var(--text); padding: 8px 14px;
  border-radius: 8px; font-size: 13px; font-weight: 600; font-family: inherit;
}
.btn:hover { filter: brightness(1.2); text-decoration: none; }
.btn-primary { background: var(--green-dim); border-color: var(--green-dim); color: #fff; }
.btn-danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.link { font-size: 13px; }

.admin-bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.admin-bar h1 { font-size: 22px; margin: 0; }
.admin-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.form-inline { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.form-inline input { flex: 1; min-width: 160px; }

/* Flash */
.flashes { max-width: 820px; margin: 12px auto 0; padding: 0 20px; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; font-size: 14px; }
.flash-ok { background: rgba(46,204,143,.15); color: var(--green); }
.flash-error { background: rgba(245,123,123,.15); color: var(--red); }

.foot { text-align: center; margin-top: 24px; font-size: 13px; }

/* Error pages */
.err-card {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
}
.err-code {
  font-size: 34px; font-weight: 800; letter-spacing: .04em;
  color: var(--border-hi); font-variant-numeric: tabular-nums;
}

/* ================= Custom replacements for native browser UI ============= */

/* ---- Tooltip (was: title="") ---- */
.tip {
  position: fixed; top: 0; left: 0; z-index: 60;
  display: flex; flex-direction: column; gap: 3px;
  min-width: 132px; max-width: min(280px, calc(100vw - 16px));
  padding: 9px 12px;
  background: var(--float);
  border: 1px solid var(--border-hi);
  border-radius: 9px;
  box-shadow: var(--shadow);
  font-size: 12px; line-height: 1.45;
  pointer-events: none;
  opacity: 0; visibility: hidden;
  transition: opacity .12s ease, visibility .12s ease;
}
.tip.is-open { opacity: 1; visibility: visible; }
.tip::after {
  content: ""; position: absolute; left: var(--arrow-x, 50%);
  width: 8px; height: 8px; margin-left: -4px;
  background: var(--float); border: 1px solid var(--border-hi);
  transform: rotate(45deg);
}
.tip[data-place="top"]::after { bottom: -5px; border-top: 0; border-left: 0; }
.tip[data-place="bottom"]::after { top: -5px; border-bottom: 0; border-right: 0; }

.tip-date { font-weight: 700; letter-spacing: .01em; }
.tip-state { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.tip-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--gray); flex: none; }
.tip-state.is-up { color: var(--green); }
.tip-state.is-up .tip-dot { background: var(--green); }
.tip-state.is-down { color: var(--red); }
.tip-state.is-down .tip-dot { background: var(--red); }
.tip-state.is-partial { color: var(--orange); }
.tip-state.is-partial .tip-dot { background: var(--orange); }
.tip-state.is-none { color: var(--muted); }
.tip-note { color: var(--muted); }

/* ---- Field error (was: native validation bubble) ---- */
.fielderr {
  position: fixed; top: 0; left: 0; z-index: 70;
  max-width: min(300px, calc(100vw - 16px));
  padding: 7px 11px;
  background: #3b1d22; border: 1px solid var(--red); border-radius: 8px;
  color: #ffdcdc; font-size: 12.5px; line-height: 1.45; font-weight: 500;
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: 0; visibility: hidden;
  transition: opacity .12s ease, visibility .12s ease;
}
.fielderr.is-open { opacity: 1; visibility: visible; }
.fielderr::after {
  content: ""; position: absolute; left: var(--arrow-x, 16px);
  width: 8px; height: 8px; margin-left: -4px;
  background: #3b1d22; border: 1px solid var(--red);
  transform: rotate(45deg);
}
.fielderr[data-place="bottom"]::after { top: -5px; border-bottom: 0; border-right: 0; }
.fielderr[data-place="top"]::after { bottom: -5px; border-top: 0; border-left: 0; }

input[aria-invalid="true"], textarea[aria-invalid="true"] {
  border-color: var(--red); box-shadow: 0 0 0 3px rgba(245, 123, 123, .16);
}

/* ---- Modal (was: window.confirm) ---- */
.modal {
  padding: 0; border: 0; background: transparent; color: var(--text);
  max-width: 100vw; max-height: 100vh; overflow: visible;
}
.modal::backdrop { background: rgba(4, 7, 12, .72); }
.modal[open] { animation: modal-pop .15s ease-out; }
.modal-box {
  width: min(420px, calc(100vw - 32px));
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 22px 24px 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
}
.modal-title { margin: 0; font-size: 16px; font-weight: 700; }
.modal-text { margin: 8px 0 0; color: var(--muted); font-size: 13.5px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.modal-actions .btn { min-width: 92px; text-align: center; }
@keyframes modal-pop {
  from { opacity: 0; transform: translateY(6px) scale(.985); }
  to { opacity: 1; transform: none; }
}

/* ---- Select (was: native dropdown popup) ---- */
.sel { position: relative; display: block; }
.sel-native {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; pointer-events: none; appearance: none;
  border: 0; padding: 0; box-shadow: none;
}
.sel-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; cursor: pointer; text-align: left;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: 9px 11px; font-size: 14px; font-family: inherit;
}
.sel-btn:hover { border-color: var(--border-hi); }
.sel-btn[aria-expanded="true"] { border-color: var(--blue); }
.sel-btn:focus-visible {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(77, 159, 255, .18);
}
.sel-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sel-caret {
  flex: none; width: 7px; height: 7px; margin-right: 2px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: translateY(-2px) rotate(45deg);
  transition: transform .15s ease;
}
.sel-btn[aria-expanded="true"] .sel-caret { transform: translateY(1px) rotate(225deg); }

.sel-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 50;
  margin: 0; padding: 5px; list-style: none;
  max-height: 240px; overflow-y: auto;
  background: var(--card-2); border: 1px solid var(--border-hi);
  border-radius: 10px; box-shadow: var(--shadow);
}
.sel.is-up .sel-list { top: auto; bottom: calc(100% + 6px); }
.sel-opt {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-radius: 7px; font-size: 14px; cursor: pointer;
}
.sel-opt.is-active { background: rgba(77, 159, 255, .15); }
.sel-opt[aria-selected="true"]::after {
  content: "\2713"; color: var(--green); font-weight: 700; font-size: 12px;
}
.sel-opt[aria-disabled="true"] { opacity: .45; cursor: default; }

/* Day-count label toggles (wide = full history, narrow = 30) */
.d-narrow { display: none; }

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  .page { padding: 20px 14px 48px; }

  .hero { padding: 12px 0 18px; }
  .hero h1 { font-size: 24px; }
  .hero-icon { width: 46px; height: 46px; font-size: 22px; }
  .subtle { font-size: 13px; }

  .card { padding: 16px 16px; border-radius: 10px; }
  .card-head { flex-wrap: wrap; gap: 8px; }

  /* Show only the most recent 30 days; hide the older bars */
  .bars { height: 30px; gap: 2px; }
  .bars .bar:nth-last-child(n+31) { display: none; }
  .d-wide { display: none; }
  .d-narrow { display: inline; }

  /* Notices / history rows stack nicely */
  .notice { flex-wrap: wrap; gap: 8px; }
  .notice-title { flex-basis: 100%; order: 3; }
  .history-list li { flex-wrap: wrap; gap: 4px; }
  .history-list li .small { flex-basis: 100%; }

  /* Forms stack vertically */
  .row { flex-direction: column; gap: 14px; }
  .form-inline { flex-direction: column; }
  .form-inline input { width: 100%; }

  /* Admin */
  .admin-bar h1 { font-size: 19px; }
  .admin-actions { width: 100%; }
  .admin-actions .btn, .admin-actions form { flex: 1; }
  .admin-actions .btn { text-align: center; }

  /* Tables scroll horizontally instead of overflowing */
  .table { display: block; overflow-x: auto; white-space: nowrap; }

  /* Custom UI layers */
  .tip { max-width: calc(100vw - 24px); }
  .modal-box { padding: 20px 18px 16px; }
  .modal-actions { flex-direction: column-reverse; gap: 8px; }
  .modal-actions .btn { width: 100%; }
  .sel-list { max-height: 200px; }
}

/* Larger touch targets on coarse pointers */
@media (pointer: coarse) {
  .btn { padding: 10px 16px; }
  .bar { min-width: 3px; }
  .sel-btn { padding: 11px 12px; }
  .sel-opt { padding: 11px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .bar, .tip, .fielderr, .sel-caret { transition: none; }
  .modal[open] { animation: none; }
}
