:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-hover: #273549;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --error: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --priority: #fbbf24;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}

/* ----- header ----- */
.app-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand a {
  color: var(--text);
  text-decoration: none;
  font-size: 1.1rem;
  font-weight: 700;
}

.view-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  flex: 1;
}
.view-tabs a {
  padding: 6px 12px;
  color: var(--muted);
  text-decoration: none;
  border-radius: 6px;
  font-size: 0.9rem;
}
.view-tabs a:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.view-tabs a.active { background: var(--accent); color: #fff; }

.user-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ----- main view ----- */
.view-root {
  padding: 20px;
  min-height: calc(100vh - 64px);
}

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

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}
.section-header h2 { margin: 0; font-size: 1.3rem; }

/* ----- panel ----- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}
.panel h3 {
  margin: 0 0 16px;
  font-size: 1rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ----- buttons ----- */
button, .btn, .btn-primary, .btn-secondary, .btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
}
button, .btn, .btn-primary { background: var(--accent); color: #fff; }
button:hover, .btn:hover, .btn-primary:hover { background: var(--accent-hover); }
button:disabled, .btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-secondary:hover { background: rgba(255,255,255,0.04); border-color: var(--accent); }

.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: #dc2626; }

.btn-small { padding: 4px 10px; font-size: 0.8rem; }

/* ----- form ----- */
label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 4px;
}

input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

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

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  align-items: flex-end;
}

/* ----- tables ----- */
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
th {
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  background: rgba(0,0,0,0.15);
}
tr:hover td { background: rgba(255,255,255,0.02); }

/* ----- badges ----- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(255,255,255,0.1);
}
.badge-priority { background: var(--priority); color: #1f2937; }
.badge-client { background: var(--success); color: #fff; }
.badge-prospect { background: var(--accent); color: #fff; }
.badge-error { background: var(--error); color: #fff; }
.badge-warning { background: var(--warning); color: #1f2937; }
.badge-muted { background: var(--border); color: var(--muted); }

/* ----- kpi cards ----- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.kpi-card {
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.kpi-card .label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.kpi-card .value {
  font-size: 1.6rem;
  font-weight: 700;
  margin-top: 6px;
}
.kpi-card .unit {
  font-size: 0.8rem;
  color: var(--muted);
  margin-left: 4px;
}

/* ----- modal ----- */
.modal-root {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h2 { margin: 0 0 16px; font-size: 1.2rem; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ----- toast ----- */
.toast-root {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  font-size: 0.9rem;
  pointer-events: auto;
  animation: slide-in 0.2s;
}
.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--error); }
.toast-info { border-left: 4px solid var(--accent); }

@keyframes slide-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ----- misc ----- */
.muted { color: var(--muted); }
.error { color: var(--error); }
.success { color: var(--success); }
.warning { color: var(--warning); }

.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

.filter-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}
.filter-bar input, .filter-bar select {
  width: auto;
  min-width: 160px;
}

.alert-banner {
  padding: 10px 16px;
  background: rgba(239,68,68,0.1);
  border: 1px solid var(--error);
  border-radius: 8px;
  margin-bottom: 16px;
  color: var(--error);
}
