:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-hover: #f0f1f4;
  --border: #d1d5db;
  --text: #1f2937;
  --text-muted: #6b7280;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #16a34a;
  --warning: #ca8a04;
  --radius: 8px;
}

[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #22263a;
  --border: #2a2e3f;
  --text: #e1e4ed;
  --text-muted: #8b8fa3;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --danger: #ef4444;
  --danger-hover: #f87171;
  --success: #22c55e;
  --warning: #eab308;
}

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

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

/* Login Page */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 400px;
}

.login-container h1 {
  text-align: center;
  margin-bottom: 1.5rem;
  font-size: 1.5rem;
}

/* Header */

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

.header-left h1 {
  font-size: 1.25rem;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

#username-display {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Main */

main {
  padding: 1.5rem 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.status-text {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.loading, .empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}

/* Forms */

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

.form-group label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.form-group.checkbox label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

input[type="text"],
input[type="password"],
input[type="url"],
input[type="email"] {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s;
}

input:focus {
  border-color: var(--primary);
}

/* Buttons */

.btn {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s;
}

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

.btn-sm {
  padding: 0.25rem 0.75rem;
  font-size: 0.8125rem;
}

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

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

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

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

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

/* Error */

.error-message {
  color: var(--danger);
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
  padding: 0.5rem;
  background: rgba(239, 68, 68, 0.1);
  border-radius: var(--radius);
}

/* Table */

.slots-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.slots-table th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.slots-table td {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

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

.domain-name {
  font-weight: 500;
  white-space: nowrap;
}

/* Slot Cells */

.slot-cell {
  cursor: pointer;
  border-radius: 4px;
  padding: 0.375rem 0.75rem;
  transition: background 0.15s;
  min-width: 120px;
}

.slot-cell:hover {
  background: var(--surface-hover);
}

.slot-empty {
  color: var(--text-muted);
  font-style: italic;
}

.slot-active {
  color: var(--success);
  font-weight: 500;
}

.slot-deploying {
  color: var(--warning);
}

.slot-error {
  color: var(--danger);
}

.slot-legacy {
  color: var(--warning);
  font-weight: 500;
}

.slot-legacy .slot-badge {
  display: inline-block;
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(234, 179, 8, 0.15);
  color: var(--warning);
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  margin-left: 0.35rem;
  vertical-align: middle;
}

.slot-url {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Star button */

.star-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0;
  margin-right: 0.5rem;
  color: var(--text-muted);
  transition: color 0.15s, transform 0.15s;
  vertical-align: middle;
}

.star-btn:hover {
  transform: scale(1.2);
}

.star-btn.starred {
  color: #facc15;
}

/* Drag handle */

.drag-handle {
  cursor: grab;
  color: var(--text-muted);
  font-size: 1rem;
  padding: 0.25rem 0.5rem 0.25rem 0;
  user-select: none;
  opacity: 0.4;
  transition: opacity 0.15s;
  vertical-align: middle;
}

.drag-handle:hover {
  opacity: 1;
}

.drag-handle:active {
  cursor: grabbing;
}

/* Drag-and-drop row states */

tr.dragging {
  opacity: 0.4;
}

tr.drag-over td {
  border-top: 2px solid var(--primary);
}

/* Domain actions */

.domain-actions {
  white-space: nowrap;
}

.domain-actions .btn {
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
}

/* Modal */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal[hidden] {
  display: none;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.modal-header h2 {
  font-size: 1.125rem;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

.modal-slot-info {
  background: var(--bg);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

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

/* Detail modal */

.detail-info {
  background: var(--bg);
  padding: 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.detail-row {
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  word-break: break-all;
}

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

.detail-row a {
  color: var(--primary);
  text-decoration: none;
}

.detail-row a:hover {
  text-decoration: underline;
}

/* Company sub-rows */

.company-row td {
  padding: 0.35rem 1rem !important;
  font-size: 0.8125rem;
  background: var(--bg);
}

.company-row .company-path {
  color: var(--primary);
  font-family: monospace;
  font-size: 0.8125rem;
}

.company-row .company-job {
  color: var(--text);
}

.company-row .company-status {
  font-size: 0.75rem;
}

.company-row .company-status.active {
  color: var(--success);
}

.company-row .company-status.error {
  color: var(--danger);
}

.company-row .company-status.deploying {
  color: var(--warning);
}

.add-company-btn {
  background: none;
  border: 1px dashed var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  transition: color 0.15s, border-color 0.15s;
}

.add-company-btn:hover {
  color: var(--primary);
  border-color: var(--primary);
}

/* Input with prefix (for path input) */

.input-with-prefix {
  display: flex;
  align-items: center;
}

.input-prefix {
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  padding: 0.5rem 0.5rem;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-family: monospace;
  line-height: 1;
}

.input-with-prefix input {
  border-radius: 0 var(--radius) var(--radius) 0 !important;
}

.form-hint {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Detail edit mode */

.detail-edit {
  background: var(--bg);
  padding: 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.detail-edit .detail-row {
  margin-bottom: 0.75rem;
  font-size: 0.875rem;
  word-break: break-all;
}

/* Theme toggle */

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.2rem 0.5rem;
  line-height: 1;
  transition: background 0.15s;
}

.theme-toggle:hover {
  background: var(--surface-hover);
}

/* Spinner */

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 0.5rem;
}
