:root {
  --bg: #f7f7f9;
  --surface: #ffffff;
  --text: #18181b;
  --text-muted: #71717a;
  --border: #e4e4e7;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --success: #16a34a;
  --warn: #dc2626;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.04);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans",
    "Yu Gothic UI", "Yu Gothic", "Meiryo", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

main {
  min-height: 100vh;
  padding: 24px 16px;
  max-width: 1100px;
  margin: 0 auto;
}

h1, h2 {
  margin: 0;
  font-weight: 600;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  padding: 10px 16px;
  font-size: 14px;
  background: var(--accent);
  color: white;
  font-family: inherit;
  font-weight: 500;
}
button:hover {
  filter: brightness(0.95);
}
button.ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
button:disabled {
  opacity: 0.5;
  cursor: wait;
}

input {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
}
input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

/* --- Login --- */
.login-screen {
  min-height: 80vh;
  display: grid;
  place-items: center;
}
.login-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 36px 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card h1 {
  font-size: 28px;
  margin-bottom: 4px;
}
.login-sub {
  margin: 0 0 24px;
  color: var(--text-muted);
  font-size: 14px;
}
.login-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.error {
  color: var(--warn);
  font-size: 13px;
  margin: 8px 0 0;
}

/* --- Dashboard --- */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}
.dashboard-header h1 {
  font-size: 20px;
}
.month-label {
  color: var(--text-muted);
  font-size: 14px;
}

.month-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.month-nav select {
  padding: 6px 10px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
}
.month-nav select:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}
button.ghost.icon {
  padding: 6px 12px;
  font-size: 18px;
  line-height: 1;
}
button.ghost.icon:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.dashboard-actions {
  display: flex;
  gap: 8px;
}

.stale-banner {
  background: #fef3c7;
  border: 1px solid #fde68a;
  color: #92400e;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 16px;
}

/* --- Cards --- */
.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
@media (max-width: 720px) {
  .cards {
    grid-template-columns: 1fr;
  }
}
.card {
  background: var(--surface);
  border-radius: 10px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.card h2 {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 8px;
}
.card-value {
  margin: 0;
  font-size: 28px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.card-note {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}
.card.exceeded .card-value {
  color: var(--warn);
}
.card.under .card-value {
  color: var(--success);
}
.card.trial .card-value {
  text-decoration: line-through;
  opacity: 0.55;
}
.card.trial .card-note {
  color: var(--accent);
  font-weight: 500;
}

.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-left: 4px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: help;
  position: relative;
  vertical-align: middle;
  user-select: none;
}
.info-icon:hover,
.info-icon:focus {
  background: var(--accent-soft);
  color: var(--accent);
  outline: none;
}
.info-tooltip {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: 260px;
  padding: 10px 12px;
  background: var(--text);
  color: white;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  box-shadow: var(--shadow);
  z-index: 10;
  text-align: left;
  white-space: normal;
}
.info-tooltip::before {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-bottom-color: var(--text);
}
.info-icon:hover .info-tooltip,
.info-icon:focus .info-tooltip {
  display: block;
}

/* --- Chart --- */
.chart-section,
.history-section {
  background: var(--surface);
  border-radius: 10px;
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.chart-section h2,
.history-section h2 {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 12px;
}
.chart-wrap {
  position: relative;
  height: 300px;
}

/* --- History table --- */
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.history-table th,
.history-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.history-table th {
  font-weight: 500;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.history-table td:nth-child(2),
.history-table td:nth-child(3) {
  text-align: right;
}
.history-table th:nth-child(2),
.history-table th:nth-child(3) {
  text-align: right;
}
.history-table tr.current td {
  font-weight: 600;
}

.dashboard-footer {
  margin-top: 12px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
}
.dashboard-footer p {
  margin: 2px 0;
}

.loading {
  text-align: center;
  padding: 80px 0;
  color: var(--text-muted);
}
