*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

:root {
  --bg: #f7f4f0;
  --surface: #ffffff;
  --border: #e0d8ce;
  --text: #2c2418;
  --text-muted: #7a6f62;
  --accent: #c0392b;
  --accent-light: #e74c3c;
  --warn: #e67e22;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --radius: 10px;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Auth */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}

.auth-card h1 {
  font-size: 1.4rem;
  margin-bottom: 0.25rem;
}

.auth-card p.subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.auth-card .tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.auth-card .tab-btn {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: none;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-muted);
  transition: all 0.15s;
}

.auth-card .tab-btn.active {
  background: var(--text);
  color: white;
  border-color: var(--text);
}

/* Forms */
.form-group {
  margin-bottom: 1rem;
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: var(--text-muted);
}

input[type="email"],
input[type="password"],
input[type="text"],
input[type="datetime-local"] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 1.25rem;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
  font-weight: 500;
}

.btn-primary {
  background: var(--accent);
  color: white;
  width: 100%;
}

.btn-primary:hover { opacity: 0.88; }

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--border); }

.btn-danger {
  background: #c0392b;
  color: white;
}

.btn-danger:hover { opacity: 0.88; }

.error-msg {
  color: var(--accent-light);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

/* App layout */
#app-screen {
  display: none;
  flex-direction: column;
  min-height: 100vh;
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

header h1 { font-size: 1.1rem; font-weight: 600; }

header .user-info {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.main-content {
  display: flex;
  flex: 1;
  gap: 0;
}

/* Diagram panels */
.diagram-area {
  flex: 1;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.diagram-area h2 {
  font-size: 1rem;
  color: var(--text-muted);
  font-weight: 500;
}

.svg-panels {
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
  justify-content: center;
}

.svg-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.svg-panel h3 {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.svg-container {
  position: relative;
  aspect-ratio: 3 / 8;
  height: clamp(260px, calc(100dvh - 160px), 680px);
  width: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  touch-action: none;
  cursor: zoom-in;
}

.svg-container.zoomed          { cursor: grab; }
.svg-container.zoomed:active   { cursor: grabbing; }

.zoom-reset {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0,0,0,0.52);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 13px;
  line-height: 22px;
  text-align: center;
  z-index: 10;
  touch-action: manipulation;
  transition: background 0.15s;
}
.zoom-reset:hover { background: rgba(0,0,0,0.75); }

.svg-container svg {
  width: 100%;
  height: 100%;
  display: block;
}

.svg-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}

/* Site dots */
.site-dot {
  cursor: pointer;
  transition: r 0.1s;
}

.site-dot:hover { r: 3; }

.site-dot.highlighted {
  r: 3.5;
  filter: drop-shadow(0 0 4px rgba(0,0,0,0.4));
}

/* Warning ring */
.warn-ring {
  pointer-events: none;
  fill: none;
  stroke: var(--warn);
  stroke-width: 2.5;
  stroke-dasharray: 6 3;
  opacity: 0.85;
  animation: spin 4s linear infinite;
}

@keyframes spin {
  from { transform-origin: center; transform: rotate(0deg); }
  to   { transform-origin: center; transform: rotate(360deg); }
}

/* Tooltip */
.tooltip {
  position: absolute;
  background: rgba(0,0,0,0.82);
  color: #fff;
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: 4px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 100;
  transform: translate(-50%, -110%);
}

/* History panel */
.history-panel {
  width: 280px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.history-panel h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}

.history-item {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: background 0.1s;
}

.history-item:hover { background: var(--bg); }
.history-item.active { background: #fef3ee; }

.history-item .dot-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.history-item .details {
  flex: 1;
  min-width: 0;
}

.history-item .date {
  font-size: 0.8rem;
  font-weight: 500;
}

.history-item .meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item .delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1rem;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
  flex-shrink: 0;
}

.history-item .delete-btn:hover { color: var(--accent); background: #ffeaea; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}

.modal h2 {
  font-size: 1.1rem;
  margin-bottom: 1.25rem;
}

.modal-footer {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.25rem;
  justify-content: flex-end;
}

/* Responsive */
@media (max-width: 640px) {
  .main-content { flex-direction: column; }
  .history-panel { width: 100%; border-left: none; border-top: 1px solid var(--border); max-height: 260px; }
  .svg-panels { gap: 1rem; }
  .svg-container { height: clamp(200px, calc(48dvh - 60px), 360px); }
  header { padding: 0.6rem 1rem; }
  .diagram-area { padding: 1rem; }
}
