:root {
  --bg: #f4f8fd;
  --card: #ffffff;
  --ink: #081736;
  --dim: #5f6c82;
  --bd: #d9e2ef;
  --navy: #08275d;
  --blue: #0867df;
  --grn: #138a2e;
  --red: #dc2838;
  --amb: #a76408;
  color-scheme: light;
}

html { background: var(--bg); }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.side {
  width: 238px;
  padding: 24px 18px;
  background: linear-gradient(180deg, #08275d 0%, #041b45 100%);
  box-shadow: 10px 0 34px rgba(4, 27, 69, .09);
}
.side .lg { margin-bottom: 24px; letter-spacing: .04em; }
.side .lg .sq {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  color: transparent;
  background: #fff url("icon-192.png") center / cover no-repeat;
  border-radius: 11px;
}
.side a {
  display: flex;
  min-height: 46px;
  align-items: center;
  gap: 11px;
  padding: 10px 13px;
  color: #bed1ee;
  border-radius: 13px;
  line-height: 1.15;
}
.side a.on { color: #fff; background: rgba(255,255,255,.15); }
.side a.on::before { left: -18px; background: #69b1ff; }
.nav-ico { width: 22px; flex: 0 0 22px; text-align: center; font-size: 17px; }
.side .u { border: 1px solid rgba(255,255,255,.08); }

.main { margin-left: 238px; padding: 30px 34px 72px; }
.main > h1, .main > .top h1 { letter-spacing: -.025em; }
.box, .drop, .res {
  border-color: var(--bd);
  border-radius: 20px;
  box-shadow: 0 8px 28px rgba(8, 39, 93, .045);
}
.btn, .cta {
  min-height: 44px;
  background: var(--blue);
  border-radius: 14px;
  box-shadow: 0 8px 18px rgba(8, 103, 223, .16);
}
input, select { min-height: 44px; border-color: var(--bd); border-radius: 12px; }
table { font-variant-numeric: tabular-nums; }
tr:hover { background: #f7faff; }

.network-state {
  position: fixed;
  z-index: 1000;
  top: 12px;
  left: 50%;
  display: none;
  max-width: calc(100vw - 28px);
  transform: translateX(-50%);
  padding: 9px 14px;
  color: #714500;
  background: #fff0c8;
  border: 1px solid #e6c675;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(8, 23, 54, .18);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}
.network-state.is-offline { display: block; }

body.auth-page {
  min-height: 100vh;
  padding: 24px;
  background: radial-gradient(circle at 50% 0%, #164a96 0, #08275d 44%, #041b45 100%);
}
.auth-page .card {
  width: min(420px, 100%);
  padding: 38px 34px;
  border: 1px solid rgba(255,255,255,.5);
  border-radius: 26px;
  box-shadow: 0 30px 80px rgba(1, 14, 39, .45);
}
.auth-page .lg { font-size: 1rem; letter-spacing: .04em; }
.auth-page .lg .sq {
  width: 42px;
  height: 42px;
  color: transparent;
  background: url("icon-192.png") center / cover no-repeat;
  border-radius: 13px;
}
.auth-page input { min-height: 50px; background: #f7faff; }
.auth-page form > button { min-height: 50px; border-radius: 15px; box-shadow: 0 9px 22px rgba(8, 103, 223, .22); }
.auth-page .pw-toggle { min-height: 38px; width: 40px; color: var(--blue); box-shadow: none; }

@media (max-width: 900px) {
  body:not(.auth-page) { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  .side {
    position: fixed;
    z-index: 900;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    display: grid;
    width: 100%;
    height: calc(68px + env(safe-area-inset-bottom));
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 3px;
    padding: 5px 7px max(5px, env(safe-area-inset-bottom));
    background: rgba(255,255,255,.98);
    border-top: 1px solid var(--bd);
    box-shadow: 0 -10px 28px rgba(8, 27, 69, .1);
    backdrop-filter: blur(16px);
  }
  .side .lg, .side .sp, .side .u { display: none; }
  .side a {
    min-width: 0;
    min-height: 54px;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    padding: 4px 2px;
    color: #45536a;
    border-radius: 14px;
    font-size: 10.5px;
    font-weight: 750;
    text-align: center;
  }
  .side a.on { color: var(--blue); background: #dcecff; }
  .side a.on::before { display: none; }
  .nav-ico { width: auto; flex-basis: auto; font-size: 20px; line-height: 1; }

  .main {
    width: 100%;
    max-width: none;
    margin-left: 0;
    padding: 0 16px 28px;
  }
  .main > h1:first-child,
  .main > .top:first-child {
    margin: 0 -16px 18px;
    padding: max(26px, env(safe-area-inset-top)) 20px 24px;
    color: #fff;
    background: var(--navy);
    border-radius: 0 0 28px 28px;
  }
  .main > h1:first-child { font-size: 1.55rem; text-align: center; }
  .main > .top:first-child { min-height: 112px; align-items: center; gap: 14px; }
  .main > .top:first-child h1 { color: #fff; font-size: 1.5rem; }
  .main > .top:first-child .seg { max-width: 100%; overflow-x: auto; background: rgba(255,255,255,.13); }
  .main > .top:first-child .seg a { color: #dbeafe; }
  .main > .top:first-child .seg a.on { color: var(--navy); }
  .main > .top.month-top:first-child { flex-direction: column; flex-wrap: nowrap; align-items: stretch; }
  .month-top .period-actions { width: 100%; max-width: 100%; min-width: 0; }
  .month-top .period-actions .seg { min-width: 0; max-width: 100%; flex: 1 1 auto; }
  .month-top .period-actions .cta { flex: 0 0 auto; }
  .main > .sub { margin: -7px 0 16px; padding: 0 4px; line-height: 1.45; }

  .grid { gap: 12px; margin-top: 14px; }
  .box { padding: 15px; border-radius: 18px; }
  .b3, .b5, .b6, .b7, .b12 { grid-column: span 12; }
  .ind { display: grid; width: 100%; grid-template-columns: 1fr 1fr; }
  .ind .box { min-width: 0; }
  .frow { display: grid; grid-template-columns: 1fr; }
  .frow input, .frow select, .frow .btn { width: 100%; max-width: none !important; }
  .btn, .cta { min-height: 50px; }
  .box { overflow-x: auto; }
  table { min-width: 620px; }
  .mgrid { grid-template-columns: 1fr 1fr; }
  .drop { margin-top: 14px; padding: 30px 16px; }
  .addrow { display: grid; grid-template-columns: 1fr; }
  .addrow input, .addrow select, .addrow button { width: 100%; min-width: 0; }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
  .cmask { padding: 14px; align-items: flex-end; }
  .calc, .cdetail { width: 100%; max-height: 82vh; border-radius: 24px 24px 16px 16px; }
  .network-state { top: max(10px, env(safe-area-inset-top)); }
}

@media (max-width: 420px) {
  .main { padding-right: 13px; padding-left: 13px; }
  .main > h1:first-child, .main > .top:first-child { margin-right: -13px; margin-left: -13px; }
  .ind { grid-template-columns: 1fr; }
  .mgrid { grid-template-columns: 1fr; }
  .auth-page .card { padding: 30px 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
