* { box-sizing: border-box; }

:root {
  --color-primary: #1a2b4c;
  --color-primary-hover: #24396a;
  --color-primary-soft: #eef1f8;
  --color-bg: #eef1f6;
  --color-surface: #ffffff;
  --color-border: #e2e5ec;
  --color-text: #1a1f29;
  --color-text-muted: #667085;
  --color-success: #157347;
  --color-success-bg: #eaf7f0;
  --color-danger: #c1352c;
  --color-danger-bg: #fdeceb;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 6px 20px rgba(16, 24, 40, 0.08);
}

html, body {
  height: 100%;
}

body {
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", -apple-system, BlinkMacSystemFont, sans-serif;
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--color-primary); }

/* ---------- Header ---------- */

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--color-primary);
  color: #fff;
  padding: 14px 18px;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.app-logo {
  display: block;
  flex-shrink: 0;
  border-radius: 6px;
}

.app-header h1 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

main {
  padding: 16px 16px 48px;
  max-width: 960px;
  margin: 0 auto;
}

.app-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.header-button {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #fff;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

.header-button:hover {
  background: rgba(255, 255, 255, 0.22);
}

.nav-menu {
  position: relative;
}

.nav-menu-toggle {
  padding: 9px 12px;
  display: inline-flex;
  align-items: center;
}

.hamburger-icon {
  display: inline-flex;
  flex-direction: column;
  justify-content: space-between;
  width: 18px;
  height: 13px;
}

.hamburger-icon span {
  display: block;
  height: 2px;
  width: 100%;
  background: currentColor;
  border-radius: 1px;
}

.nav-menu-list {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 6px;
  min-width: 160px;
  display: none;
  flex-direction: column;
  gap: 2px;
  z-index: 20;
}

.nav-menu-list.is-open {
  display: flex;
}

.nav-menu-item {
  display: block;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--color-text);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
}

.nav-menu-item:hover {
  background: var(--color-primary-soft);
}

.nav-menu-item.is-active {
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

/* ---------- Buttons & links ---------- */

.link-button, .link-button:visited {
  color: rgba(255, 255, 255, 0.9);
  background: none;
  border: none;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 4px;
}

.link-button:hover { color: #fff; }

.button, button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
}

.button:hover, button:hover {
  background: var(--color-primary-hover);
}

.button:active, button:active {
  transform: translateY(1px);
}

.button:focus-visible, button:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid #4f7cff;
  outline-offset: 2px;
}

.button-secondary, .button-secondary:visited {
  background: var(--color-surface);
  color: var(--color-primary);
  border: 1px solid var(--color-border);
}

.button-secondary:hover {
  background: var(--color-primary-soft);
}

.button-block {
  display: flex;
  width: 100%;
  text-align: center;
}

.button-sm {
  padding: 8px 14px;
  font-size: 0.9rem;
}

.new-button {
  margin: 4px 0 16px;
  box-shadow: var(--shadow-sm);
}

.danger-button {
  background: var(--color-danger);
}

.danger-button:hover {
  background: #a02922;
}

.inline-form {
  display: inline;
}

/* ---------- Cards / shared surfaces ---------- */

.card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.overdue-box {
  background: #fff8e6;
  border: 1px solid #f5dd9a;
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 16px;
}

.overdue-box h2 {
  font-size: 0.95rem;
  margin: 0 0 8px;
  color: #8a6d1e;
}

.overdue-box ul {
  margin: 0;
  padding-left: 20px;
}

.overdue-box li + li {
  margin-top: 4px;
}

/* ---------- Filter / search ---------- */

.filter-form {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.filter-row-main {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: stretch;
}

.filter-row-main input[type="text"] {
  flex: 1 1 180px;
  min-width: 0;
}

.filter-toggle {
  background: var(--color-primary-soft);
  color: var(--color-primary);
  border: 1px solid var(--color-border);
  font-weight: 500;
}

.filter-toggle:hover {
  background: #e3e8f4;
}

.filter-toggle-icon {
  display: inline-block;
  transition: transform 0.15s ease;
}

.filter-toggle[aria-expanded="true"] .filter-toggle-icon {
  transform: rotate(180deg);
}

.filter-advanced {
  display: none;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px 14px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--color-border);
}

.filter-advanced.is-open {
  display: grid;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.filter-field-range {
  grid-column: 1 / -1;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.filter-field-range .filter-field {
  flex: 1;
  min-width: 0;
}

.filter-field-range .range-sep {
  padding-bottom: 9px;
  color: var(--color-text-muted);
}

.filter-form input, .filter-form select {
  padding: 9px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  color: var(--color-text);
  background: #fff;
  width: 100%;
}

@media (min-width: 700px) {
  .filter-advanced {
    display: grid !important;
    grid-template-columns: 1fr 1fr auto auto;
    align-items: flex-end;
  }
  .filter-field-range {
    grid-column: auto;
  }
  .filter-toggle {
    display: none;
  }
}

/* ---------- Table ---------- */

.table-scroll {
  overflow-x: auto;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  background: var(--color-surface);
}

.call-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.call-table th {
  background: #f7f8fb;
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 0.8rem;
}

.call-table th, .call-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  font-size: 0.9rem;
  white-space: nowrap;
}

.call-table tbody tr:hover {
  background: #f5f7fb;
}

.call-table a {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 500;
}

.call-table a:hover {
  text-decoration: underline;
}

.status-pending { background: #fff9e6; }
.status-accepted { background: #eaf3ff; }
.status-declined { background: #fdeeed; }
.status-other { background: #f6f7f9; }

.call-table tbody tr.status-pending:hover { background: #fdf2cf; }
.call-table tbody tr.status-accepted:hover { background: #ddebfe; }
.call-table tbody tr.status-declined:hover { background: #fbe1df; }
.call-table tbody tr.status-other:hover { background: #eceef1; }

/* ---------- Quick links ---------- */

.quick-links {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.quick-links-title {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--color-text-muted);
  text-transform: uppercase;
  margin: 0 0 10px;
}

.quick-links-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.quick-links-empty {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin: 0 0 10px;
}

.quick-link-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--color-primary-soft);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 5px 6px 5px 12px;
  font-size: 0.85rem;
}

.quick-link-item a {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 500;
}

.quick-link-item a:hover {
  text-decoration: underline;
}

.quick-link-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 50%;
  background: rgba(26, 43, 76, 0.08);
  color: var(--color-text-muted);
  border: none;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  flex-shrink: 0;
}

.quick-link-remove:hover {
  background: rgba(193, 53, 44, 0.15);
  color: var(--color-danger);
}

.quick-link-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 10px;
  border-top: 1px solid var(--color-border);
}

.quick-link-form input {
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  flex: 1 1 140px;
  min-width: 0;
}

.quick-link-form button {
  flex-shrink: 0;
}

/* ---------- Messages ---------- */

.success {
  color: var(--color-success);
  background: var(--color-success-bg);
  border: 1px solid #bfe6cf;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-weight: 500;
  font-size: 0.9rem;
}

.error {
  color: var(--color-danger);
  background: var(--color-danger-bg);
  border: 1px solid #f4c6c2;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-weight: 500;
  font-size: 0.9rem;
}

/* ---------- Login / signup ---------- */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px 16px;
}

.login-box {
  background: var(--color-surface);
  padding: 36px 32px 28px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.login-box h1 {
  font-size: 1.15rem;
  text-align: center;
  margin: 0 0 20px;
}

.login-box .success,
.login-box .error {
  width: 100%;
  margin-bottom: 16px;
  text-align: center;
}

.login-box form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.login-box label {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  margin-top: 6px;
}

.login-box input {
  padding: 11px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  width: 100%;
}

.login-box button[type="submit"] {
  margin-top: 14px;
}

.switch-link {
  width: 100%;
  text-align: center;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
  font-size: 0.9rem;
}

.switch-link .button {
  margin-top: 4px;
}

/* ---------- Call form ---------- */

.call-form {
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  padding: 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.call-form label {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-bottom: 4px;
  font-weight: 500;
}

.call-form input, .call-form select, .call-form textarea {
  padding: 11px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  margin-bottom: 14px;
  width: 100%;
  font-family: inherit;
  background: #fff;
}

.call-form textarea {
  resize: vertical;
}

#contact_area_other {
  display: none;
}

.form-actions {
  margin-top: 6px;
}

.delete-form {
  margin-top: 16px;
  text-align: right;
}

/* ---------- Stats ---------- */

.stat-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.stat-tile {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  text-align: center;
}

.stat-tile-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--color-primary);
}

.stat-tile-label {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin-top: 4px;
}

.stat-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 18px 20px;
  margin-bottom: 20px;
}

.stat-card h2 {
  font-size: 1rem;
  margin: 0 0 4px;
}

.stat-subtitle {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin: 0 0 18px;
}

.stat-empty {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  padding: 8px 0;
}

.stat-bar-row {
  margin-bottom: 14px;
}

.stat-bar-row:last-child {
  margin-bottom: 0;
}

.stat-bar-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
  font-size: 0.88rem;
  gap: 8px;
}

.stat-bar-label {
  font-weight: 500;
  color: var(--color-text);
}

.stat-bar-meta {
  font-weight: 600;
  color: var(--color-primary);
  white-space: nowrap;
}

.stat-bar-count {
  font-weight: 400;
  color: var(--color-text-muted);
  font-size: 0.78rem;
  margin-left: 6px;
}

.stat-bar-track {
  background: var(--color-primary-soft);
  border-radius: 999px;
  height: 12px;
  overflow: hidden;
}

.stat-bar-fill {
  background: var(--color-primary);
  height: 100%;
  border-radius: 999px;
}

@media (max-width: 480px) {
  .app-header h1 { font-size: 0.95rem; }
  .login-box { padding: 28px 20px 22px; }
  .delete-form { text-align: stretch; }
  .delete-form button { width: 100%; }
  .stat-tile-value { font-size: 1.25rem; }
  .stat-tile { padding: 10px; }
  .stat-summary { gap: 8px; }
}
