:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --text: #0f172a;
  --text-muted: #475569;
  --border: #e2e8f0;
  --primary: #0f766e;
  --primary-hover: #115e59;
  --primary-soft: rgba(15, 118, 110, 0.12);
  --accent: #0284c7;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #0b1120;
    --surface: #131c31;
    --surface-alt: #1e293b;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #26334d;
    --primary: #14b8a6;
    --primary-hover: #2dd4bf;
    --primary-soft: rgba(20, 184, 166, 0.16);
    --accent: #38bdf8;
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  }
}

html[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #131c31;
  --surface-alt: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #26334d;
  --primary: #14b8a6;
  --primary-hover: #2dd4bf;
  --primary-soft: rgba(20, 184, 166, 0.16);
  --accent: #38bdf8;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

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

a:hover {
  text-decoration: underline;
}

.container {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 18px;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.topbar-inner {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--text);
  text-decoration: none !important;
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.brand-name .accent {
  color: var(--primary);
}

.brand-tag {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Main Content */
.main-content {
  flex: 1;
  padding-top: 24px;
  padding-bottom: 48px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.92rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.16s ease;
  text-decoration: none !important;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.84rem;
  border-radius: 8px;
}

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

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

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

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

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: var(--surface-alt);
  color: var(--text);
}

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

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}

/* Cards & Grid */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.page-header p {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(275px, 1fr));
  gap: 16px;
}

.tool-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  transition: transform 0.15s ease, border-color 0.15s ease;
  position: relative;
}

.tool-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
}

.tool-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.tool-icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.45rem;
  background: var(--primary-soft);
  flex-shrink: 0;
}

.pin-btn {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pin-btn.pinned {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary);
}

.tool-title {
  font-size: 1.08rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text);
}

.tool-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
}

.tool-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Panels & Forms */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.panel h2, .panel h3 {
  margin-bottom: 12px;
  font-size: 1.15rem;
}

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

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.form-group label {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="time"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

/* Tables responsive */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

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

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

th {
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface-alt);
}

/* Badges & Alerts */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  background: var(--surface-alt);
  color: var(--text-muted);
}

.badge-success { background: rgba(22, 163, 74, 0.15); color: var(--success); }
.badge-warning { background: rgba(217, 119, 6, 0.15); color: var(--warning); }
.badge-danger  { background: rgba(220, 38, 38, 0.15); color: var(--danger); }

.alert {
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 16px;
  font-size: 0.92rem;
  border: 1px solid var(--border);
  background: var(--surface-alt);
}

.alert-success { border-color: var(--success); color: var(--success); }
.alert-danger  { border-color: var(--danger); color: var(--danger); }

/* Filter Pills */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.pill {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

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

/* Stage plot & Signature canvas */
.interactive-canvas {
  width: 100%;
  border: 2px dashed var(--border);
  border-radius: 12px;
  background: var(--surface-alt);
  touch-action: none;
  cursor: crosshair;
}

/* Footer & Mobile Bottom Nav */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 20px 0;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

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

.mobile-bottom-nav {
  display: none;
}

@media (max-width: 720px) {
  .hide-mobile { display: none !important; }
  .brand-tag { display: none; }
  .main-content { padding-bottom: 84px; }
  .site-footer { padding-bottom: 84px; }
  .mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 62px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 60;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .mb-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.74rem;
    color: var(--text-muted);
    gap: 2px;
    text-decoration: none !important;
  }
  .mb-item.active {
    color: var(--primary);
    font-weight: 700;
  }
  .mb-item span { font-size: 1.2rem; }
}

@media print {
  .topbar, .mobile-bottom-nav, .site-footer, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .panel { box-shadow: none; border: 1px solid #ccc; }
}
