/* =========================================================================
   HortiTrak Admin — Navy / Teal theme
   Deliberately distinct from the main HortiTrak app (green).
   ========================================================================= */

:root {
  --navy: #1e293b;
  --navy-dark: #0f172a;
  --teal: #0d9488;
  --teal-light: #14b8a6;
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #ffffff;

  --status-active: #10b981;
  --status-trial: #f59e0b;
  --status-suspended: #ef4444;
  --status-cancelled: #6b7280;

  --plan-starter: #6366f1;
  --plan-professional: #8b5cf6;
  --plan-enterprise: #ec4899;

  --bg-page: #f1f5f9;
  --card-bg: #ffffff;
  --border-color: #e2e8f0;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-card: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-card-hover: 0 4px 12px rgba(15, 23, 42, 0.1);

  --sidebar-width: 260px;
  --topbar-height: 64px;
}

/* ---------------------------------------------------------------------
   Reset & base
   --------------------------------------------------------------------- */

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

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-primary);
  background-color: var(--bg-page);
  font-size: 15px;
  line-height: 1.5;
}

a {
  color: var(--teal);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

ul, ol {
  list-style: none;
}

button {
  font-family: inherit;
  cursor: pointer;
}

h1, h2, h3 {
  color: var(--navy);
  font-weight: 600;
}

h2 {
  font-size: 1.15rem;
}

h3 {
  font-size: 1rem;
}

/* ---------------------------------------------------------------------
   Layout
   --------------------------------------------------------------------- */

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

.admin-main {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
}

/* ---------------------------------------------------------------------
   Sidebar
   --------------------------------------------------------------------- */

.admin-sidebar {
  width: var(--sidebar-width);
  background-color: var(--navy-dark);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 24px 20px 4px;
}

.brand-logo {
  font-size: 1.3rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.02em;
}

.brand-badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background-color: var(--teal);
  color: #ffffff;
  padding: 2px 8px;
  border-radius: 999px;
}

.sidebar-tagline {
  padding: 0 20px 20px;
  font-size: 0.72rem;
  color: var(--sidebar-text);
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
  padding-bottom: 20px;
  margin: 0 4px 12px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 8px 12px;
  gap: 2px;
  flex: 1;
}

.sidebar-nav a {
  color: var(--sidebar-text);
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.92rem;
  text-decoration: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar-nav a:hover {
  background-color: rgba(148, 163, 184, 0.1);
  color: #ffffff;
  text-decoration: none;
}

.sidebar-nav a.active {
  background-color: var(--teal);
  color: var(--sidebar-text-active);
}

.sidebar-footer {
  padding: 16px 20px 24px;
  border-top: 1px solid rgba(148, 163, 184, 0.15);
}

.sidebar-footer a {
  color: var(--sidebar-text);
  font-size: 0.85rem;
}

.sidebar-footer a:hover {
  color: #ffffff;
}

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 14px;
  left: 16px;
  z-index: 200;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background-color: var(--navy-dark);
  border: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.sidebar-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background-color: #ffffff;
  border-radius: 1px;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.5);
  z-index: 90;
}

.sidebar-backdrop.visible {
  display: block;
}

/* ---------------------------------------------------------------------
   Top bar
   --------------------------------------------------------------------- */

.admin-topbar {
  height: var(--topbar-height);
  background-color: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--navy);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 16px;
}

.user-name {
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.btn-logout {
  color: var(--teal);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.btn-logout:hover {
  background-color: var(--bg-page);
  text-decoration: none;
}

.admin-content {
  padding: 28px;
  flex: 1;
}

/* ---------------------------------------------------------------------
   Flash messages
   --------------------------------------------------------------------- */

.flash-messages {
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid transparent;
}

.flash-success {
  background-color: #ecfdf5;
  color: #047857;
  border-color: #a7f3d0;
}

.flash-error {
  background-color: #fef2f2;
  color: #b91c1c;
  border-color: #fecaca;
}

/* ---------------------------------------------------------------------
   Stat cards
   --------------------------------------------------------------------- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 24px;
}

.stat-card {
  background-color: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-left: 4px solid var(--teal);
}

.stat-card-active {
  border-left-color: var(--status-active);
}

.stat-card-trial {
  border-left-color: var(--status-trial);
}

.stat-card-revenue {
  border-left-color: var(--plan-professional);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--navy);
}

/* ---------------------------------------------------------------------
   Panels & dashboard grid
   --------------------------------------------------------------------- */

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
}

.panel {
  background-color: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.panel-wide {
  grid-column: 1 / -1;
}

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

.panel-link {
  font-size: 0.85rem;
  font-weight: 600;
}

.panel-body {
  padding: 20px 22px;
}

.panel-note {
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.panel-highlight {
  border: 2px solid var(--teal-light);
  margin-bottom: 20px;
}

.panel-form {
  max-width: 720px;
}

/* ---------------------------------------------------------------------
   Activity feed
   --------------------------------------------------------------------- */

.activity-feed {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.activity-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

.activity-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.activity-action {
  font-weight: 600;
  color: var(--navy);
  font-size: 0.92rem;
}

.activity-details {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.activity-time {
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* ---------------------------------------------------------------------
   Health indicators
   --------------------------------------------------------------------- */

.health-summary {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.9rem;
}

.health-summary li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.health-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--text-muted);
}

.health-healthy {
  background-color: var(--status-active);
}

.health-error {
  background-color: var(--status-suspended);
}

.health-unknown {
  background-color: var(--text-muted);
}

.health-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------------------------------------------------------------------
   Chart placeholder
   --------------------------------------------------------------------- */

.chart-placeholder {
  height: 180px;
  border-radius: var(--radius-md);
  background: repeating-linear-gradient(
    135deg,
    rgba(13, 148, 136, 0.06),
    rgba(13, 148, 136, 0.06) 10px,
    rgba(13, 148, 136, 0.03) 10px,
    rgba(13, 148, 136, 0.03) 20px
  );
  border: 1px dashed var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-muted);
  padding: 20px;
}

/* ---------------------------------------------------------------------
   Progress bars
   --------------------------------------------------------------------- */

.progress-bar {
  margin-top: 10px;
  height: 8px;
  border-radius: 999px;
  background-color: var(--border-color);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background-color: var(--teal);
  border-radius: 999px;
}

/* ---------------------------------------------------------------------
   Tables
   --------------------------------------------------------------------- */

.table-wrapper {
  background-color: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow-x: auto;
  margin-bottom: 24px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th {
  text-align: left;
  padding: 14px 20px;
  background-color: var(--bg-page);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table td {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  vertical-align: middle;
}

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

.data-table tbody tr:hover {
  background-color: var(--bg-page);
}

.pricing-table input {
  max-width: 160px;
}

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

.btn-link {
  color: var(--teal);
  font-weight: 600;
  font-size: 0.85rem;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 20px !important;
  font-style: italic;
}

/* ---------------------------------------------------------------------
   Badges
   --------------------------------------------------------------------- */

.badge {
  display: inline-block;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #ffffff;
  white-space: nowrap;
}

.badge-status-active { background-color: var(--status-active); }
.badge-status-trial { background-color: var(--status-trial); }
.badge-status-suspended { background-color: var(--status-suspended); }
.badge-status-cancelled { background-color: var(--status-cancelled); }

.badge-plan-starter { background-color: var(--plan-starter); }
.badge-plan-professional { background-color: var(--plan-professional); }
.badge-plan-enterprise { background-color: var(--plan-enterprise); }

/* ---------------------------------------------------------------------
   Content header (search/filter bars + primary action)
   --------------------------------------------------------------------- */

.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1;
}

.filter-bar input[type="text"] {
  flex: 1;
  min-width: 200px;
}

.filter-bar input,
.filter-bar select {
  padding: 9px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  background-color: var(--card-bg);
  color: var(--text-primary);
}

/* ---------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  border: 1px solid transparent;
  text-decoration: none;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
  white-space: nowrap;
}

.btn:hover {
  text-decoration: none;
}

.btn-primary {
  background-color: var(--teal);
  color: #ffffff;
}

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

.btn-secondary {
  background-color: var(--card-bg);
  color: var(--navy);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--bg-page);
}

.btn-success {
  background-color: var(--status-active);
  color: #ffffff;
}

.btn-success:hover {
  opacity: 0.9;
}

.btn-danger {
  background-color: var(--status-suspended);
  color: #ffffff;
}

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

.btn-block {
  width: 100%;
}

.inline-form {
  display: inline-block;
}

/* ---------------------------------------------------------------------
   Forms
   --------------------------------------------------------------------- */

.admin-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--navy);
}

.form-row input,
.form-row select,
.form-row textarea {
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-family: inherit;
  color: var(--text-primary);
  background-color: var(--card-bg);
}

.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
}

.form-row input:disabled {
  background-color: var(--bg-page);
  color: var(--text-muted);
}

.form-row textarea {
  resize: vertical;
}

.form-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.form-actions {
  display: flex;
  gap: 12px;
  padding-top: 6px;
}

.info-box {
  background-color: #f0fdfa;
  border: 1px solid #99f6e4;
  border-radius: var(--radius-md);
  padding: 16px 18px;
}

.info-box h3 {
  color: var(--navy);
  margin-bottom: 8px;
}

.info-box ul {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-left: 18px;
  list-style: disc;
}

.info-box li {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.code-block {
  background-color: var(--navy-dark);
  color: #a7f3d0;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.85rem;
  overflow-x: auto;
  margin: 12px 0;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------------------------------------------------------------------
   Tenant detail header
   --------------------------------------------------------------------- */

.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.detail-header h2 {
  font-size: 1.4rem;
  margin-bottom: 4px;
}

.detail-subdomain {
  margin-bottom: 10px;
  font-size: 0.9rem;
}

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

.detail-list {
  display: grid;
  grid-template-columns: 140px 1fr;
  row-gap: 12px;
  column-gap: 12px;
  font-size: 0.9rem;
}

.detail-list dt {
  font-weight: 600;
  color: var(--text-secondary);
}

.detail-list dd {
  color: var(--text-primary);
}

/* ---------------------------------------------------------------------
   Login page
   --------------------------------------------------------------------- */

.login-body {
  background: linear-gradient(160deg, var(--navy-dark) 0%, var(--navy) 55%, var(--teal) 130%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 20px;
  width: 100%;
}

.login-card {
  background-color: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
}

.login-brand {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin-bottom: 6px;
}

.login-brand .brand-logo {
  color: var(--navy);
  font-size: 1.6rem;
}

.login-subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: 24px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-form label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--navy);
}

.login-form input {
  padding: 12px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
}

.login-form input:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
}

.login-form .btn {
  margin-top: 6px;
  padding: 12px 18px;
}

.login-footer {
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.8rem;
  text-align: center;
}

/* =========================================================================
   Responsive
   ========================================================================= */

@media (max-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .panel-wide {
    grid-column: auto;
  }
}

@media (max-width: 860px) {
  .sidebar-toggle {
    display: flex;
  }

  .admin-sidebar {
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
  }

  .admin-sidebar.open {
    transform: translateX(0);
  }

  .admin-main {
    margin-left: 0;
  }

  .admin-topbar {
    padding-left: 68px;
  }
}

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

  .admin-content {
    padding: 18px;
  }

  .admin-topbar {
    padding-right: 16px;
  }

  .content-header {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-bar {
    flex-direction: column;
  }

  .filter-bar input,
  .filter-bar select,
  .filter-bar button {
    width: 100%;
  }

  .detail-header {
    flex-direction: column;
  }

  .detail-actions {
    width: 100%;
  }

  .detail-actions .btn,
  .detail-actions form {
    flex: 1;
  }

  .detail-actions .btn {
    width: 100%;
  }

  .detail-list {
    grid-template-columns: 1fr;
  }

  .detail-list dt {
    margin-top: 8px;
  }

  .form-actions {
    flex-direction: column;
  }

  .form-actions .btn {
    width: 100%;
  }

  .table-wrapper {
    border-radius: var(--radius-md);
  }

  .login-card {
    padding: 32px 24px;
  }
}
