:root {
  --ink: #173b3a;
  --accent: #126e68;
  --accent-dark: #0e5a55;
  --muted: #5c7471;
  --line: #e4ecea;
  --bg: #f4f8f7;
  --card: #ffffff;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.app-shell { display: flex; min-height: 100vh; }
.app-nav {
  width: 240px;
  background: #0f2f2d;
  color: #d7e6e4;
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  gap: 18px;
}
.brand-logo { display: block; width: 100%; height: auto; }
.app-nav > .brand { width: 100%; text-decoration: none; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  border-radius: 8px;
  padding: 6px 9px;
  letter-spacing: 0.5px;
}
.brand-text { font-weight: 700; color: #fff; }
.app-nav nav { display: flex; flex-direction: column; gap: 2px; }
.app-nav nav a {
  color: #b7cfcc;
  text-decoration: none;
  padding: 9px 10px;
  border-radius: 6px;
  font-size: 14px;
}
.app-nav nav a:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.app-nav nav a.active { background: var(--accent); color: #fff; }
.nav-footer { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.nav-user { font-size: 12px; color: #93b3af; word-break: break-all; }

.app-content { flex: 1; padding: 28px 32px; max-width: 1200px; }
.page-header { margin-bottom: 20px; }
.page-header h1 { margin: 0 0 4px; font-size: 22px; }
.page-header p { margin: 0; color: var(--muted); font-size: 14px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-card span { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; }
.stat-card strong { font-size: 22px; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 18px;
}
.panel h2 { margin: 0 0 12px; font-size: 16px; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.tag {
  background: #e6f2f0;
  color: var(--accent-dark);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 600;
}
.muted { color: var(--muted); }

.button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
}
.button:hover { border-color: #c9d9d6; }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.button.primary:hover { background: var(--accent-dark); }
.button.ghost { background: transparent; color: inherit; border-color: rgba(255,255,255,0.2); }
.button.small { padding: 5px 9px; font-size: 12px; }

.inline-form { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.inline-form input, .inline-form select, textarea, .login-card input {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}
.form-error, .login-error { color: #8b2c25; font-size: 13px; margin: 6px 0 0; }
.code { background: #0f2f2d; color: #d7e6e4; padding: 14px; border-radius: 8px; overflow: auto; font-size: 13px; }

/* Login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  width: min(380px, calc(100vw - 40px));
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 26px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card h1 { margin: 4px 0 6px; font-size: 20px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.login-brand .brand-text { color: var(--ink); }

/* Assistant (same design language as 4warding.us) */
.link-assistant { position: fixed; right: 20px; bottom: 20px; z-index: 900; color: var(--ink); }
.link-assistant [hidden] { display: none !important; }
.link-assistant button {
  min-width: 0; padding: 0; border: 1px solid #c9d9d6; border-radius: 6px; background: #fff;
  box-shadow: 0 4px 18px rgba(20, 54, 52, 0.16); color: var(--ink); cursor: pointer;
}
.link-assistant button:focus-visible, .link-assistant textarea:focus-visible { outline: 3px solid rgba(21,130,119,0.35); outline-offset: 2px; }
.link-assistant-toggle {
  width: max-content; min-width: 0; height: 48px; display: inline-flex; align-items: center; gap: 9px;
  padding: 0 16px !important; background: var(--accent) !important; border-color: var(--accent) !important;
  color: #fff !important; font-size: 14px; font-weight: 700;
}
.link-assistant-toggle:hover { background: var(--accent-dark) !important; }
.link-assistant-panel {
  position: absolute; right: 0; bottom: 60px; display: flex; flex-direction: column;
  width: min(390px, calc(100vw - 32px)); height: min(560px, calc(100vh - 110px)); min-height: 300px;
  border: 1px solid #c9d9d6; border-radius: 8px; background: #fff;
  box-shadow: 0 12px 40px rgba(20, 54, 52, 0.2); overflow: hidden;
}
.link-assistant-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 64px; padding: 12px 14px; border-bottom: 1px solid var(--line); background: #f5f9f8;
}
.link-assistant-header h2 { margin: 0; font-size: 16px; }
.link-assistant-header p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.link-assistant-header-actions { display: flex; gap: 7px; }
.link-assistant-header-actions button { width: 32px; height: 32px; }
.link-assistant-messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 9px; }
.link-assistant-message { margin: 0; padding: 9px 11px; border-radius: 8px; font-size: 14px; line-height: 1.45; background: #f5f9f8; border: 1px solid var(--line); white-space: pre-wrap; }
.link-assistant-message.user { background: #e6f2f0; border-color: #cfe4e1; align-self: flex-end; }
.link-assistant-message.loading { color: var(--muted); font-style: italic; }
.link-assistant-message.error { border-color: #efc4c0; background: #fff3f1; color: #8b2c25; }
.link-assistant-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.link-assistant-form textarea { flex: 1; resize: none; }
.link-assistant-send { background: var(--accent) !important; border-color: var(--accent) !important; color: #fff !important; padding: 0 14px !important; font-weight: 600; }

@media (max-width: 860px) {
  .stat-grid, .stat-grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .app-nav { width: 190px; }
  .app-content { padding: 20px 16px; }
}

@media (max-width: 520px) {
  .link-assistant { right: 12px; bottom: 12px; }
  .link-assistant-panel { position: fixed; right: 12px; bottom: 72px; width: calc(100vw - 24px); height: min(560px, calc(100dvh - 92px)); }
}
