:root {
  --brand-navy: #1F4E79;
  --brand-gold: #E8A33D;
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fb;
  --text-primary: #1a1a2e;
  --text-secondary: #666;
  --text-muted: #999;
  --border: #e0e0e0;
  --border-dark: #d0d0d0;
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 16px rgba(0,0,0,0.12);
  --radius: 6px;
  --transition: all 0.2s ease;
}

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

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

/* Login page */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--brand-navy), #0f2a48);
  padding: 20px;
}

.login-card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.login-logo {
  margin-bottom: 32px;
}

.login-logo svg {
  margin-bottom: 12px;
}

.login-logo .brand {
  font-size: 24px;
  font-weight: 700;
  color: var(--brand-navy);
  margin-bottom: 4px;
}

.login-logo .sub {
  font-size: 13px;
  color: var(--text-secondary);
}

.login-card h1 {
  font-size: 20px;
  margin-bottom: 24px;
  color: var(--text-primary);
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.login-card input {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
}

.login-card input:focus {
  outline: none;
  border-color: var(--brand-navy);
  box-shadow: 0 0 0 3px rgba(31, 78, 121, 0.1);
}

.login-card button {
  padding: 12px;
  background: var(--brand-navy);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.login-card button:hover {
  background: #0f2a48;
}

.login-card button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.login-card .err {
  background: #fef2f2;
  color: #c00;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid #fcc;
  font-size: 13px;
  margin-bottom: 12px;
}

.lang-row {
  margin-top: 20px;
  font-size: 13px;
}

.lang-row a {
  color: var(--brand-navy);
  text-decoration: none;
  cursor: pointer;
}

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

/* App header */
.app-header {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  box-shadow: var(--shadow);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  color: var(--brand-navy);
  font-size: 16px;
  min-width: 200px;
}

.app-header nav {
  display: flex;
  gap: 16px;
  flex: 1;
}

.app-header nav a {
  padding: 8px 12px;
  color: var(--text-secondary);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
  font-size: 14px;
}

.app-header nav a:hover,
.app-header nav a.active {
  color: var(--brand-navy);
  border-bottom-color: var(--brand-gold);
}

.app-header .right {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: auto;
}

.role-pill {
  background: var(--bg-secondary);
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--brand-navy);
}

.username {
  font-size: 13px;
  font-weight: 500;
}

.lang-toggle,
.logout-btn {
  padding: 8px 12px;
  font-size: 13px;
  border: 1px solid var(--border);
  background: white;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
}

.logout-btn {
  background: #fff0f0;
  color: #c00;
  border-color: #fcc;
}

.logout-btn:hover {
  background: #ffe0e0;
}

/* Main content */
.app-main {
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
}

.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-secondary);
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  font-size: 13px;
}

thead {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-dark);
}

th {
  padding: 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-primary);
}

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

tbody tr:hover {
  background: var(--bg-secondary);
}

/* Buttons */
.btn {
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary {
  background: var(--brand-navy);
  color: white;
}

.btn-primary:hover {
  background: #0f2a48;
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: #eee;
}

/* Forms */
input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--brand-navy);
  box-shadow: 0 0 0 3px rgba(31, 78, 121, 0.1);
}

/* Utility */
.err {
  background: #fef2f2;
  color: #c00;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid #fcc;
  font-size: 13px;
}

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

/* Cards */
.card {
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card h3 {
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--text-primary);
}

/* Badges */
.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

.badge.status-settled {
  background: #d4edda;
  color: #155724;
}

.badge.status-current {
  background: #d1ecf1;
  color: #0c5460;
}

.badge.status-opportunity {
  background: #fff3cd;
  color: #856404;
}

.badge.status-done {
  background: #e2e3e5;
  color: #383d41;
}

/* Responsive */
@media (max-width: 768px) {
  .app-header {
    flex-wrap: wrap;
  }

  .app-header nav {
    width: 100%;
    order: 3;
    gap: 8px;
    margin-top: 8px;
  }

  .app-header .right {
    margin-left: 0;
    order: 4;
    width: 100%;
  }

  table {
    font-size: 12px;
  }

  th, td {
    padding: 8px;
  }

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

/* ============== AI 助手 floating chat widget ============== */
.chat-fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-gold, #E8A33D) 0%, var(--brand-navy, #1F4E79) 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 24px;
  box-shadow: 0 6px 20px rgba(31, 78, 121, 0.4);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
}
.chat-fab:hover { transform: scale(1.08); }
.chat-fab.open { background: var(--brand-navy, #1F4E79); }

.chat-panel {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 420px;
  max-width: calc(100vw - 40px);
  height: min(640px, calc(100vh - 120px));
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(31, 78, 121, 0.25);
  display: none;
  flex-direction: column;
  z-index: 998;
  overflow: hidden;
  border: 1px solid var(--border, #e1e5ea);
}
.chat-panel.open { display: flex; }

.chat-header {
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--brand-navy, #1F4E79) 0%, #163a5c 100%);
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.chat-header .title {
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-header .clear-btn {
  background: rgba(255, 255, 255, 0.18);
  border: none;
  color: #fff;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
}
.chat-header .clear-btn:hover { background: rgba(255, 255, 255, 0.28); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  background: #fafbfd;
  font-size: 13px;
}
.chat-msg { margin-bottom: 12px; display: flex; flex-direction: column; }
.chat-msg.user { align-items: flex-end; }
.chat-msg.bot { align-items: flex-start; }

.chat-bubble {
  max-width: 88%;
  padding: 8px 12px;
  border-radius: 12px;
  line-height: 1.55;
  word-wrap: break-word;
}
.chat-msg.user .chat-bubble {
  background: var(--brand-navy, #1F4E79);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg.bot .chat-bubble {
  background: #fff;
  color: var(--text, #222);
  border: 1px solid var(--border, #e1e5ea);
  border-bottom-left-radius: 4px;
}
.chat-bubble.thinking {
  background: var(--brand-gold, #E8A33D);
  color: #4a3a00;
  font-weight: 600;
  font-style: italic;
}
.chat-bubble code {
  background: rgba(0,0,0,0.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: monospace;
  font-size: 12px;
}
.chat-bubble strong { color: var(--brand-navy, #1F4E79); }
.chat-msg.user .chat-bubble strong { color: var(--brand-gold, #E8A33D); }
.chat-bubble ul, .chat-bubble ol { margin: 4px 0 4px 18px; padding: 0; }
.chat-bubble li { margin: 2px 0; }
.chat-bubble a { color: var(--brand-navy, #1F4E79); cursor: pointer; }
.chat-bubble.error { background: #fff3f3; color: #c0392b; border-color: #e8a3a3; }

.chat-msg .meta {
  font-size: 10px;
  color: var(--text-3, #97a3b3);
  margin-top: 3px;
}

.chat-input-row {
  padding: 10px 12px;
  border-top: 1px solid var(--border, #e1e5ea);
  background: #fff;
  display: flex;
  gap: 6px;
}
.chat-input-row textarea {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border, #e1e5ea);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  resize: none;
  min-height: 36px;
  max-height: 80px;
}
.chat-input-row textarea:focus {
  outline: 2px solid var(--brand-gold, #E8A33D);
  outline-offset: -1px;
  border-color: var(--brand-navy, #1F4E79);
}
.chat-input-row button {
  padding: 8px 16px;
  background: var(--brand-navy, #1F4E79);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
}
.chat-input-row button:hover { background: #163a5c; }
.chat-input-row button:disabled { opacity: 0.5; cursor: not-allowed; }

.chat-empty-hints {
  color: var(--text-3, #97a3b3);
  text-align: center;
  padding: 16px;
  font-size: 12px;
}

@media (max-width: 600px) {
  .chat-fab { width: 48px; height: 48px; bottom: 14px; right: 14px; }
  .chat-panel { bottom: 0; right: 0; left: 0; width: 100%; max-width: 100%; height: 80vh; border-radius: 14px 14px 0 0; }
  .chat-bubble { font-size: 13px; }
}
