/* ============================================
   Travian Commander — Modern SaaS Theme
   Inspired by Linear/Vercel/Shadcn
   ============================================ */

:root {
  --bg: #fafafa;
  --bg-subtle: #f4f4f5;
  --bg-muted: #e4e4e7;
  --surface: #ffffff;
  --border: #e4e4e7;
  --border-hover: #d4d4d8;
  --text: #09090b;
  --text-secondary: #71717a;
  --text-muted: #a1a1aa;
  --primary: #18181b;
  --primary-hover: #27272a;
  --primary-fg: #fafafa;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #eff6ff;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --sidebar-w: 260px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.5;
}

/* === Layout === */
.app {
  display: flex;
  min-height: 100vh;
}

/* === Sidebar === */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--primary);
  color: var(--primary-fg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-text {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.02em;
}

.sidebar-nav {
  padding: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 13px;
  transition: all 0.15s;
}

.nav-item:hover { background: var(--bg-subtle); color: var(--text); }
.nav-item.active { background: var(--bg-subtle); color: var(--text); font-weight: 600; }

.sidebar-accounts {
  flex: 1;
  padding: 4px 8px;
  overflow-y: auto;
}

.sidebar-account {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font: inherit;
  color: var(--text);
}

.sidebar-account:hover { background: var(--bg-subtle); }
.sidebar-account.selected { background: var(--accent-light); }

.sidebar-account-name {
  font-weight: 500;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-villages-section {
  padding: 4px 8px;
  border-top: 1px solid var(--border);
}

.sidebar-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 8px 12px 4px;
}

.sidebar-villages {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-village {
  display: flex;
  flex-direction: column;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  border: none;
  background: none;
  text-align: left;
  font: inherit;
  color: var(--text);
  transition: all 0.15s;
}

.sidebar-village:hover { background: var(--bg-subtle); }
.sidebar-village.selected { background: var(--accent-light); }

.sidebar-village-name {
  font-size: 13px;
  font-weight: 500;
}

.sidebar-village-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.health-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.health-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 2px var(--success-light);
}

/* === Main === */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-left h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.header-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.main-content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--primary);
  color: var(--primary-fg);
  border-color: var(--primary);
}

.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-outline {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-outline:hover:not(:disabled) { background: var(--bg-subtle); border-color: var(--border-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  padding: 6px 8px;
}

.btn-ghost:hover:not(:disabled) { background: var(--bg-subtle); color: var(--text); }

.btn-danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--border);
}

.btn-danger:hover:not(:disabled) { background: var(--danger-light); border-color: var(--danger); }

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* === Cards === */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

/* === Status Pills === */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid transparent;
}

.pill-idle, .pill-online { background: var(--success-light); color: var(--success); border-color: #bbf7d0; }
.pill-traveling, .pill-running, .pill-connecting { background: var(--accent-light); color: var(--accent); border-color: #bfdbfe; }
.pill-error { background: var(--danger-light); color: var(--danger); border-color: #fecaca; }
.pill-paused, .pill-off { background: var(--bg-subtle); color: var(--text-muted); border-color: var(--border); }

/* === Forms === */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.required { color: var(--danger); }

.form-group input, .form-group select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s;
}

.form-group input:focus, .form-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group input::placeholder { color: var(--text-muted); }

.form-message {
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 12px;
  display: none;
}

.form-message.visible { display: block; }
.form-message.ok { background: var(--success-light); color: var(--success); }
.form-message.err { background: var(--danger-light); color: var(--danger); }

.form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}

/* === Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  padding: 16px;
}

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

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-sm { max-width: 360px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 15px;
  font-weight: 600;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
}

.btn-close:hover { background: var(--bg-subtle); color: var(--text); }

.modal-body { padding: 20px; }
.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* === Accounts Grid === */
.accounts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.account-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  cursor: pointer;
  transition: all 0.15s;
}

.account-card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow);
}

.account-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.account-card-title {
  font-weight: 600;
  font-size: 14px;
}

.account-card-meta {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.account-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* === Empty State === */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state svg { margin-bottom: 16px; opacity: 0.4; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty-state p { font-size: 14px; margin-bottom: 16px; }

/* === Toolbar === */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
}

/* === Stats Grid === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 15px;
  font-weight: 600;
}

/* === Resources === */
.resources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.resource {
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
}

.resource-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.resource-value {
  font-size: 15px;
  font-weight: 600;
  margin-top: 2px;
}

.resource-wood .resource-value { color: #92400e; }
.resource-clay .resource-value { color: #b45309; }
.resource-iron .resource-value { color: #475569; }
.resource-crop .resource-value { color: #15803d; }

/* === Tables === */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

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

thead {
  background: var(--bg-subtle);
}

th {
  padding: 8px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

tr:last-child td { border-bottom: none; }

tr.pickable { cursor: pointer; transition: background 0.1s; }
tr.pickable:hover { background: var(--accent-light); }
tr.queued { background: var(--success-light); }

/* === Build Plan === */
.build-plan {
  margin-top: 16px;
  padding: 16px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.build-plan-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.build-plan-header h4 {
  font-size: 14px;
  font-weight: 600;
}

.build-plan-list {
  list-style: none;
  margin-bottom: 12px;
}

.build-plan-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.build-plan-item:last-child { border-bottom: none; }

.build-plan-order {
  font-weight: 700;
  color: var(--accent);
  min-width: 24px;
}

.build-plan-name { flex: 1; }

.build-plan-actions {
  display: flex;
  gap: 4px;
}

.build-plan-add {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.build-plan-add label {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.build-plan-add input, .build-plan-add select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-size: 13px;
  background: var(--surface);
}

/* === Task Toggle === */
.task-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  cursor: pointer;
  font-size: 13px;
}

.task-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

/* === Logs === */
.logs-list {
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.log-line {
  display: flex;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  background: var(--bg-subtle);
  border-left: 3px solid var(--border);
}

.log-line.success { border-left-color: var(--success); }
.log-line.error { border-left-color: var(--danger); }
.log-line.warn { border-left-color: var(--warning); }

.log-time {
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
  min-width: 70px;
}

/* === Section === */
.section {
  margin-bottom: 20px;
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* === Village Cards === */
.villages-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.village-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  cursor: pointer;
  transition: all 0.15s;
}

.village-card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow);
}

.village-card-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}

.village-card-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* === Text utilities === */
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.font-mono { font-family: 'SF Mono', 'Fira Code', monospace; }

.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }

/* === Responsive === */
@media (max-width: 768px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .main-header { padding: 12px 16px; }
  .main-content { padding: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .accounts-grid { grid-template-columns: 1fr; }
}
