:root {
  --primary:        #19acc1;
  --primary-dark:   #1396aa;
  --primary-darker: #0f7b8d;
  --primary-light:  #e6f9fc;
  --ink:            #1e293b;
  --muted:          #64748b;
  --line:           #e2e8f0;
  --panel:          #f8fafc;
  --surface:        #ffffff;
  --danger:         #ef4444;
  --danger-light:   #fef2f2;
  --success:        #16a34a;
  --success-light:  #f0fdf4;
  --warning:        #d97706;
  --sidebar-w:      220px;
}

*  { box-sizing: border-box; margin: 0; padding: 0; }

body {
  color: var(--ink);
  background: var(--panel);
  font-family: 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP',
               -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

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

/* ── Layout ─────────────────────────────────────── */

.app { min-height: 100vh; display: flex; }

.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.brand {
  padding: 18px 16px 16px;
  background: var(--primary);
  border-bottom: 1px solid rgba(0,0,0,0.08);
  flex-shrink: 0;
}

.brand strong {
  display: block;
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.brand span {
  display: block;
  color: rgba(255,255,255,0.72);
  font-size: 11px;
  margin-top: 3px;
}

.sidebar nav { flex: 1; padding: 10px 8px; }

.sidebar nav a {
  display: flex;
  align-items: center;
  border-radius: 7px;
  padding: 8px 12px;
  color: #475569;
  font-weight: 600;
  font-size: 13.5px;
  margin-bottom: 1px;
  transition: background 0.12s, color 0.12s;
}

.sidebar nav a.active {
  background: var(--primary-light);
  color: var(--primary-darker);
}

.sidebar nav a:hover {
  background: #f1f5f9;
  color: var(--ink);
  text-decoration: none;
}

.sidebar nav a.active:hover { background: var(--primary-light); }

.userbox {
  border-top: 1px solid var(--line);
  padding: 12px 16px;
  background: #f8fafc;
  flex-shrink: 0;
}

.userbox strong { display: block; font-size: 13px; font-weight: 700; }

.userbox span {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
}

.userbox a {
  display: inline-block;
  margin-top: 7px;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 3px 10px;
}

.userbox a:hover { background: var(--panel); text-decoration: none; }

/* ── Main ───────────────────────────────────────── */

.main { margin-left: var(--sidebar-w); flex: 1; min-width: 0; padding: 28px 32px; }

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 18px;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--primary-light);
}

h1 { font-size: 21px; font-weight: 800; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 700; margin-bottom: 12px; }
p  { color: var(--muted); font-size: 13px; margin-top: 4px; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Cards ──────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
}

.stat {
  display: block;
  text-decoration: none;
  transition: box-shadow 0.15s, transform 0.15s;
}

.stat:hover {
  box-shadow: 0 4px 14px rgba(25,172,193,0.18);
  transform: translateY(-2px);
  text-decoration: none;
}

.stat span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); }

.stat strong {
  display: block;
  margin-top: 10px;
  font-size: 30px;
  font-weight: 800;
  color: var(--primary);
}

/* ── Buttons ────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 36px;
  padding: 7px 16px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
  font-family: inherit;
}

.btn:hover { background: #f1f5f9; border-color: #cbd5e1; text-decoration: none; }

.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { opacity: 0.88; }

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-sm { min-height: 28px; padding: 3px 10px; font-size: 12px; border-radius: 5px; }

/* ── Tables ─────────────────────────────────────── */

.table-wrap {
  width: 100%;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

th {
  background: #f8fafc;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f0fafb; }

.sort-link {
  color: var(--ink);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.sort-link:hover { color: var(--primary); text-decoration: none; }

/* ── Badge ──────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11.5px;
  font-weight: 700;
  background: var(--primary-light);
  color: var(--primary-darker);
  border: 1px solid rgba(25,172,193,0.2);
}

/* ── Alerts ─────────────────────────────────────── */

.alert {
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 18px;
  font-size: 13.5px;
  font-weight: 600;
  background: var(--success-light);
  border: 1px solid #bbf7d0;
  color: var(--success);
}

.alert.error { background: var(--danger-light); border-color: #fecaca; color: var(--danger); }

/* ── Forms ──────────────────────────────────────── */

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 18px;
  max-width: 880px;
}

.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0,1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.filter-actions { display: flex; align-items: flex-end; gap: 8px; }

label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: #374151;
  letter-spacing: 0.01em;
}

label span { margin-left: 5px; color: var(--danger); font-size: 11px; }

input, select, textarea {
  width: 100%;
  min-height: 38px;
  margin-top: 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: var(--surface);
  transition: border-color 0.12s, box-shadow 0.12s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(25,172,193,0.14);
}

textarea { min-height: 100px; resize: vertical; }

.wide, .form-actions { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; padding-top: 4px; }

.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; min-height: auto; margin-top: 0; }

/* ── Tabs ───────────────────────────────────────── */

.tabs {
  display: flex;
  border-bottom: 2px solid var(--line);
  margin-bottom: 20px;
  overflow-x: auto;
  gap: 4px;
}

.tabs a {
  white-space: nowrap;
  padding: 9px 16px;
  color: var(--muted);
  font-weight: 600;
  font-size: 13.5px;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.12s, border-color 0.12s;
  border-radius: 6px 6px 0 0;
}

.tabs a:hover { color: var(--primary); text-decoration: none; border-color: var(--primary-light); }

/* ── Detail ─────────────────────────────────────── */

.detail {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 16px;
}

.detail dt { color: var(--muted); font-size: 11.5px; font-weight: 700; letter-spacing: 0.03em; }
.detail dd { margin: 4px 0 0; font-weight: 600; font-size: 14px; }

/* ── Section ────────────────────────────────────── */

.section { margin-top: 24px; }

.section-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

/* ── Login ──────────────────────────────────────── */

.login, .setup {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--panel);
}

.form-narrow { width: 100%; max-width: 400px; }

/* ── Misc ───────────────────────────────────────── */

.inline { display: inline; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); }
.attachment-form { margin-bottom: 16px; }

.overdue    { color: var(--danger);  font-weight: 700; }
.today-date { color: var(--warning); font-weight: 700; }

/* ── Star ───────────────────────────────────────── */

.btn-star {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: #cbd5e1;
  padding: 2px 4px;
  line-height: 1;
  transition: color 0.12s;
}

.btn-star:hover, .btn-star.starred { color: #f59e0b; }

/* ── Master page ────────────────────────────────── */

.master-layout {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 24px;
  align-items: start;
}

.master-sidebar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.master-cat-link {
  display: block;
  padding: 9px 12px;
  border-radius: 6px;
  font-size: 13.5px;
  font-weight: 600;
  color: #475569;
  margin-bottom: 2px;
  transition: background 0.12s, color 0.12s;
}

.master-cat-link.active { background: var(--primary-light); color: var(--primary-darker); }
.master-cat-link:hover  { background: #f1f5f9; color: var(--ink); text-decoration: none; }

.master-content { min-width: 0; }

.color-swatch {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.15);
  vertical-align: middle;
}

/* ── Deal detail ────────────────────────────────── */

.info-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

.info-table th {
  width: 130px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 9px 12px;
  border: 1px solid var(--line);
  white-space: nowrap;
  text-align: left;
}

.info-table td {
  padding: 9px 14px;
  border: 1px solid var(--line);
  vertical-align: top;
  font-size: 13.5px;
}

.deal-title-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}

.deal-title-bar strong { font-size: 15px; }

/* ── Responsive ─────────────────────────────────── */

@media (max-width: 860px) {
  .sidebar { position: static; width: auto; min-height: auto; }
  .app { flex-direction: column; }
  .main { margin-left: 0; padding: 16px; }
  .form-grid, .filters, .detail, .master-layout { grid-template-columns: 1fr; }
  .page-header, .section-title { flex-direction: column; align-items: flex-start; }
  .cards { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 500px) {
  .cards { grid-template-columns: 1fr; }
}
