:root {
  color-scheme: light;
  --bg: #eef3f7;
  --surface: #ffffff;
  --surface-soft: #f7fafc;
  --line: #d8e1e8;
  --text: #17212b;
  --muted: #647386;
  --brand: #0f6f78;
  --brand-dark: #0d4d59;
  --brand-soft: #e7f3f4;
  --accent: #c7872a;
  --danger: #ba3636;
  --success: #237a4b;
  --shadow: 0 12px 26px rgba(23, 33, 43, 0.1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: "Yu Gothic", "Meiryo", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(15, 111, 120, 0.35);
  outline-offset: 2px;
}

.login-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(18px + env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom));
}
.login-panel {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}
.brand-mark {
  width: 66px;
  height: 66px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
}
.login-panel h1 { margin: 18px 0 8px; font-size: 27px; }
.login-panel p { margin: 0 0 24px; color: var(--muted); line-height: 1.7; }
.login-form { display: grid; gap: 10px; }
.login-form label { font-weight: 700; }
.login-form input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
}
.login-form button,
.upload-box button,
.secondary-button,
.small-button,
.primary-action-button,
.top-logout-button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  padding: 0 16px;
}
.form-error { min-height: 22px; color: var(--danger); }
body.public-mode .logout-action { display: none; }

.app-shell {
  min-height: 100dvh;
  display: block;
  padding-bottom: calc(78px + env(safe-area-inset-bottom));
}
.sidebar {
  position: fixed;
  z-index: 30;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.98);
  border-top: 1px solid var(--line);
  box-shadow: 0 -10px 22px rgba(23, 33, 43, 0.1);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
}
.sidebar-brand,
.ghost-button { display: none; }
.nav-list {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 4px;
  max-width: 720px;
  margin: 0 auto;
}
.nav-item {
  width: 100%;
  min-height: 54px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 4px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
}
.nav-item.active,
.nav-item:hover {
  background: var(--brand-soft);
  border-color: #bbdadd;
  color: var(--brand-dark);
}

.main {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) 14px 16px;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin: 0 -14px 12px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 12px;
  background: rgba(238, 243, 247, 0.96);
  border-bottom: 1px solid rgba(216, 225, 232, 0.8);
}
.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 12px; }
.topbar h1 { margin: 0; font-size: 24px; line-height: 1.2; }
.topbar-actions {
  display: grid;
  justify-items: end;
  gap: 6px;
  min-width: 112px;
}
.top-logout-button {
  min-height: 36px;
  padding: 0 10px;
  background: #dce6ec;
  color: var(--text);
  font-size: 12px;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  max-width: 100%;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  padding: 0 11px;
  font-size: 13px;
  white-space: nowrap;
}
.status-pill.ok { color: var(--success); border-color: #9fd5b8; }
.status-pill.warn { color: var(--danger); border-color: #dfb0b0; }

.view { display: none; }
.view.active { display: block; }
.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.metric-card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.metric-card { padding: 14px; }
.metric-card span { display: block; color: var(--muted); font-size: 13px; }
.metric-card strong { display: block; margin-top: 8px; font-size: 23px; line-height: 1.15; overflow-wrap: anywhere; }
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.panel { padding: 16px; margin-bottom: 12px; }
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.panel h2 { margin: 0; font-size: 18px; line-height: 1.35; }
.panel-note { margin: 8px 0 16px; color: var(--muted); line-height: 1.7; }
.small-button { min-height: 38px; background: var(--brand-dark); }
.secondary-button { background: var(--accent); }
.primary-action-row { align-items: stretch; }
.primary-action-button {
  width: 100%;
  min-height: 56px;
  font-size: 17px;
}
.secondary-action-button {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--brand-dark);
  font-weight: 800;
  padding: 0 14px;
}
.quick-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.data-list,
.list-empty { display: grid; gap: 8px; color: var(--muted); }
.list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.list-row strong { overflow-wrap: anywhere; }
.list-row span { color: var(--muted); font-size: 13px; }
.upload-box {
  display: grid;
  gap: 10px;
  align-items: stretch;
  margin-top: 12px;
}
.upload-box input {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 9px;
  width: 100%;
}
.action-row { margin-top: 14px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.inline-status { color: var(--muted); line-height: 1.6; overflow-wrap: anywhere; }
.secondary-tools {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
.secondary-tools summary {
  min-height: 42px;
  display: flex;
  align-items: center;
  color: var(--brand-dark);
  font-weight: 700;
}
.secondary-tools .secondary-button { margin-top: 10px; width: 100%; }
.order-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.order-form label {
  display: grid;
  gap: 6px;
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
}
.order-form input,
.order-form select,
.order-form textarea,
.month-toolbar input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
}
.order-form textarea {
  min-height: 82px;
  resize: vertical;
  line-height: 1.6;
}
.wide-field { grid-column: 1 / -1; }
.month-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}
.month-toolbar .status-pill { grid-column: 1 / -1; justify-self: start; }
.compact-metrics {
  margin-top: 12px;
  margin-bottom: 12px;
}
.work-list {
  display: grid;
  gap: 10px;
}
.work-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}
.work-card-main,
.work-card-side {
  display: grid;
  gap: 4px;
  min-width: 0;
}
.work-card-main strong,
.work-card-side b {
  overflow-wrap: anywhere;
}
.work-card-main span,
.work-card-side span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.work-card-side {
  align-content: start;
}
.ok-text { color: var(--success); }
.warn-text { color: var(--danger); }
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  -webkit-overflow-scrolling: touch;
}
table { width: 100%; border-collapse: collapse; min-width: 620px; background: #fff; }
th, td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}
th { background: var(--surface-soft); color: var(--muted); font-weight: 700; }
td { overflow-wrap: anywhere; }
.settings-grid { display: grid; gap: 12px; }
.settings-grid div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}
.settings-grid span { display: block; color: var(--muted); font-size: 13px; }
.settings-grid strong { display: block; margin-top: 4px; overflow-wrap: anywhere; }

@media (max-width: 390px) {
  .main { padding-left: 12px; padding-right: 12px; }
  .topbar { margin-left: -12px; margin-right: -12px; padding-left: 12px; padding-right: 12px; }
  .nav-item { font-size: 11px; min-height: 52px; }
  .metric-card { padding: 12px; }
  .metric-card strong { font-size: 21px; }
}

@media (min-width: 980px) {
  .app-shell {
    display: grid;
    grid-template-columns: 248px 1fr;
    padding-bottom: 0;
  }
  .sidebar {
    position: static;
    min-height: 100vh;
    background: #16252f;
    color: #fff;
    border-top: 0;
    box-shadow: none;
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    gap: 22px;
  }
  .sidebar-brand {
    display: block;
    border-bottom: 1px solid rgba(255,255,255,.16);
    padding-bottom: 18px;
  }
  .sidebar-brand strong { display: block; font-size: 24px; }
  .sidebar-brand span { color: rgba(255,255,255,.72); }
  .nav-list {
    grid-template-columns: 1fr;
    gap: 6px;
    max-width: none;
  }
  .nav-item,
  .ghost-button {
    min-height: 42px;
    text-align: left;
    color: #fff;
    padding: 0 12px;
    font-size: 15px;
    background: transparent;
  }
  .nav-item.active,
  .nav-item:hover { background: rgba(255,255,255,.13); color: #fff; border-color: transparent; }
  .ghost-button {
    display: block;
    margin-top: auto;
    border: 1px solid rgba(255,255,255,.22);
  }
  body.public-mode .ghost-button { display: none; }
  .top-logout-button { display: none; }
  .main { width: auto; max-width: none; padding: 24px; }
  .topbar {
    position: static;
    margin: 0 0 20px;
    padding: 0;
    background: transparent;
    border-bottom: 0;
  }
  .topbar h1 { font-size: 28px; }
  .metric-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
  .metric-card strong { font-size: 28px; }
  .dashboard-grid { grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); gap: 14px; }
  .panel { padding: 18px; }
  .quick-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .order-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .month-toolbar { grid-template-columns: 220px auto minmax(0, 1fr); }
  .month-toolbar .status-pill { grid-column: auto; justify-self: end; }
  .work-card { grid-template-columns: minmax(0, 1fr) minmax(150px, auto); align-items: start; }
  .work-card-side { justify-items: end; text-align: right; }
  .list-row { grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; }
  .upload-box { display: flex; flex-wrap: wrap; align-items: center; }
  .upload-box input { flex: 1 1 320px; width: auto; }
  .secondary-tools .secondary-button { width: auto; }
  table { min-width: 720px; }
}
