:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #1d2327;
  --muted: #68737d;
  --line: #dce1df;
  --accent: #116b5f;
  --accent-2: #b84a39;
  --accent-3: #2f5d9a;
  --soft: #eaf2ef;
  --warning: #8a5a00;
  --danger: #b42318;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body.auth-checking,
body.unauthenticated {
  grid-template-columns: 1fr;
}

body.auth-checking .app-shell,
body.unauthenticated .app-shell,
body.authenticated .login-screen {
  display: none;
}

.login-screen {
  min-height: 100vh;
  padding: 48px 24px;
}

.landing-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 480px);
  gap: 24px;
  align-items: stretch;
}

.landing-hero {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 28px;
  display: grid;
  gap: 24px;
  align-content: start;
  box-shadow: 0 18px 48px rgba(29, 35, 39, 0.08);
}

.landing-copy {
  display: grid;
  gap: 14px;
}

.landing-copy h2 {
  margin: 0;
  max-width: 780px;
  font-size: 36px;
  line-height: 1.18;
}

.landing-copy p {
  margin: 0;
  color: var(--muted);
  line-height: 1.75;
  font-size: 17px;
}

.landing-kicker {
  color: var(--accent) !important;
  font-weight: 800;
}

.landing-points {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.landing-points li {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfbf8;
  padding: 12px;
  color: var(--ink);
  font-weight: 700;
}

.login-panel {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 20px;
  display: grid;
  gap: 16px;
  align-content: start;
  box-shadow: 0 18px 48px rgba(29, 35, 39, 0.08);
}

.login-brand {
  align-items: flex-start;
}

.login-heading {
  display: grid;
  gap: 8px;
}

.login-heading h2 {
  margin: 0;
  font-size: 22px;
}

.login-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.login-options {
  display: grid;
  gap: 12px;
}

.login-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  gap: 12px;
  align-content: start;
}

.login-card h3 {
  margin: 0;
  font-size: 18px;
}

.telegram-login-widget {
  min-height: 46px;
}

.telegram-fallback {
  font-size: 14px;
}

.telegram-fallback code,
.login-hint code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--soft);
  color: var(--ink);
}

.wechat-login-box {
  display: grid;
  justify-items: start;
  gap: 10px;
}

.wechat-login-box img {
  width: 168px;
  height: 168px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
}

.wechat-login-box img[hidden] {
  display: none;
}

.wechat-code-box {
  display: grid;
  gap: 6px;
  width: fit-content;
  min-width: 168px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--soft);
  padding: 12px 14px;
}

.wechat-code-box span {
  color: var(--muted);
  font-size: 13px;
}

.wechat-code-box strong {
  color: var(--accent);
  font-size: 28px;
  line-height: 1;
  letter-spacing: 1px;
}

.login-hint {
  font-size: 13px;
}

.login-hint a {
  color: var(--accent);
  font-weight: 700;
}

.login-note {
  font-size: 13px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 36px;
  padding: 8px 12px;
}

button:hover {
  border-color: var(--accent);
}

.sidebar {
  min-height: 100vh;
  border-right: 1px solid var(--line);
  background: #fbfbf8;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: var(--accent);
  color: white;
  font-weight: 800;
}

.brand h1 {
  font-size: 20px;
  line-height: 1.1;
  margin: 0;
}

.brand p,
.topbar p {
  color: var(--muted);
  margin: 4px 0 0;
}

.nav {
  display: grid;
  gap: 7px;
}

.user-panel {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.user-panel span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-panel button {
  min-height: 32px;
  padding: 5px 8px;
}

.nav-item {
  text-align: left;
  min-height: 40px;
}

.nav-item.active {
  color: white;
  background: var(--ink);
  border-color: var(--ink);
}

.quick-capture {
  display: grid;
  gap: 10px;
  margin-top: auto;
}

label {
  color: var(--muted);
  font-size: 13px;
  display: grid;
  gap: 8px;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  color: var(--ink);
  padding: 9px 10px;
}

textarea {
  resize: vertical;
}

.main {
  min-width: 0;
  padding: 18px 16px;
  display: grid;
  gap: 18px;
  align-content: start;
}

.topbar {
  display: flex;
  gap: 18px;
  align-items: center;
  justify-content: space-between;
}

.topbar h2 {
  margin: 0;
  font-size: 24px;
}

.topbar-actions {
  display: grid;
  grid-template-columns: minmax(280px, 520px) auto auto;
  gap: 8px;
  align-items: center;
}

.top-user-chip {
  min-width: 136px;
  max-width: 220px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 6px 8px;
}

.top-user-chip img {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  object-fit: cover;
  background: var(--soft);
}

.top-user-chip img.empty {
  display: none;
}

.top-user-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: var(--muted);
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 18px;
}

.table-shell {
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.batch-toolbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  background: #f7faf7;
}

.selected-count {
  min-width: 72px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.batch-select {
  width: auto;
  min-width: 132px;
  min-height: 32px;
  padding: 5px 28px 5px 8px;
  border-radius: 6px;
  font-size: 13px;
}

.batch-button {
  min-height: 32px;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
}

.batch-button.secondary {
  color: var(--muted);
}

.batch-button:disabled {
  cursor: not-allowed;
  color: #99a2a8;
  background: #f3f5f3;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  min-width: 0;
}

.col-select { width: 3%; }
.col-title { width: 32%; }
.col-time { width: 15%; }
.col-category { width: 9%; }
.col-status { width: 9%; }
.col-duration { width: 8%; }
.col-quality { width: 10%; }
.col-action { width: 14%; }

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  position: sticky;
  top: 48px;
  background: #f0f3ef;
  z-index: 2;
  color: #384149;
  font-weight: 700;
  white-space: nowrap;
}

.task-checkbox {
  width: 16px;
  height: 16px;
  min-height: 16px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}

.filter-open {
  z-index: 5;
}

.header-controls {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
}

.action-header-controls {
  width: 100%;
  gap: 6px;
}

.title-header-controls {
  width: 100%;
  display: flex;
}

.sort-button {
  width: auto;
  min-height: 28px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  border-radius: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 700;
}

.sort-button:hover {
  color: var(--accent);
  border-color: transparent;
}

.sort-indicator {
  width: 14px;
  display: inline-flex;
  justify-content: center;
  color: #99a2a8;
  font-size: 12px;
  line-height: 1;
}

.sort-indicator.active {
  color: var(--accent);
}

.filter-button,
.reset-filter-button {
  width: 26px;
  min-width: 26px;
  min-height: 26px;
  height: 26px;
  padding: 0;
  border-radius: 6px;
  display: inline-grid;
  place-items: center;
  background: transparent;
  color: #7b858c;
  font-size: 13px;
  line-height: 1;
}

.filter-button:hover,
.filter-button.active,
.filter-button.open,
.reset-filter-button:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: #ffffff;
}

.filter-button.open {
  transform: rotate(180deg);
}

.filter-popover {
  position: absolute;
  left: 8px;
  top: calc(100% - 2px);
  width: min(240px, calc(100% + 100px));
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: 0 10px 28px rgba(29, 35, 39, 0.16);
  display: none;
}

.filter-popover.open {
  display: block;
}

.filter-popover[data-filter-popover="timeFilter"] {
  width: min(280px, calc(100% + 150px));
}

.plain-header {
  min-height: 28px;
  display: flex;
  align-items: center;
  font-weight: 700;
}

.column-filter {
  width: 100%;
  min-height: 28px;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
}

.title-inline-filter {
  flex: 1;
  min-width: 120px;
  max-width: 220px;
  min-height: 28px;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
}

.multi-filter {
  min-height: 116px;
  overflow-y: auto;
}

.multi-filter option {
  padding: 5px 6px;
}

.check-menu {
  display: grid;
  gap: 4px;
  max-height: 230px;
  overflow-y: auto;
}

.check-option {
  width: 100%;
  min-height: 34px;
  padding: 6px 6px 6px 8px;
  border: 0;
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18px;
  align-items: center;
  gap: 10px;
  text-align: left;
}

.single-check-menu .check-option {
  grid-template-columns: minmax(0, 1fr);
}

.check-option:hover,
.check-option:focus-visible {
  background: #eef4f1;
  outline: none;
}

.check-option.selected {
  background: #edf7f3;
  color: var(--accent);
  font-weight: 700;
}

.check-box {
  width: 16px;
  height: 16px;
  border: 1px solid #9aa5ab;
  border-radius: 4px;
  display: inline-grid;
  place-items: center;
  color: #ffffff;
  background: #ffffff;
  font-size: 12px;
  line-height: 1;
}

.check-option.selected .check-box {
  border-color: var(--accent);
  background: var(--accent);
}

.custom-date-fields {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.custom-date-fields.visible {
  display: grid;
}

.custom-date-fields label {
  font-size: 12px;
  gap: 4px;
}

.custom-date-fields input {
  min-height: 30px;
  padding: 5px 6px;
  border-radius: 6px;
  font-size: 12px;
}

td.title-cell {
  min-width: 0;
  max-width: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
}

.audio-task {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.audio-task audio {
  width: 180px;
  max-width: 100%;
  height: 32px;
}

.audio-task-label {
  white-space: nowrap;
}

td:nth-child(4) {
  white-space: nowrap;
}

td:nth-child(5),
td:nth-child(7),
td:nth-child(8),
td:nth-child(9) {
  white-space: nowrap;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--accent);
  white-space: nowrap;
}

.status.completed {
  background: #eef4ff;
  color: var(--accent-3);
}

.status.archived {
  background: #f5f1e8;
  color: var(--warning);
}

.status.deleted {
  background: #fff0ee;
  color: var(--danger);
}

.action-cell {
  position: relative;
}

.row-action-menu {
  position: relative;
  display: inline-block;
  min-width: 118px;
}

.row-action-button {
  width: 100%;
  min-height: 30px;
  padding: 4px 8px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  background: #ffffff;
}

.row-action-button:hover,
.row-action-menu.open .row-action-button {
  border-color: var(--accent);
}

.action-caret {
  color: #4c565d;
  font-size: 14px;
  line-height: 1;
}

.row-action-options {
  position: absolute;
  top: calc(100% + 4px);
  right: 8px;
  min-width: 132px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 14px 34px rgba(29, 35, 39, 0.18);
  display: none;
  z-index: 12;
}

.row-action-menu.open .row-action-options {
  display: grid;
  gap: 3px;
}

.row-action-option {
  position: relative;
  width: 100%;
  min-height: 31px;
  padding: 5px 10px;
  border: 0;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  text-align: left;
}

.row-action-option:hover,
.row-action-option:focus-visible {
  background: #edf7f3;
  color: var(--accent);
  outline: none;
}

.row-action-option.selected::before {
  content: "✓";
  display: inline-block;
  width: 16px;
  margin-right: 4px;
  color: var(--ink);
}

.action-tooltip {
  position: absolute;
  right: calc(100% + 8px);
  top: 50%;
  width: 210px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #1d2327;
  color: #ffffff;
  font-size: 12px;
  line-height: 1.45;
  white-space: normal;
  opacity: 0;
  transform: translateY(-50%);
  pointer-events: none;
  transition: opacity .12s ease, transform .12s ease;
  z-index: 13;
}

.row-action-option[data-action-value="deleted"]:hover .action-tooltip,
.row-action-option[data-action-value="deleted"]:focus-visible .action-tooltip {
  opacity: 1;
}

.stars {
  color: #d19a00;
  font-size: 15px;
  letter-spacing: 1px;
  white-space: nowrap;
}

.star-rating {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  white-space: nowrap;
}

.star-rating-button {
  width: 18px;
  height: 26px;
  min-width: 18px;
  min-height: 26px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #c6ced3;
  font-size: 17px;
  line-height: 1;
}

.star-rating-button.filled {
  color: #d19a00;
}

.star-rating-button:hover,
.star-rating-button:focus-visible {
  color: #b77f00;
  background: #fff6df;
  outline: none;
}

.empty-state {
  display: none;
  padding: 36px;
  color: var(--muted);
  text-align: center;
}

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric,
.chart-panel,
.settings-form {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.metric {
  padding: 16px;
  display: grid;
  gap: 8px;
}

.metric span {
  color: var(--muted);
}

.metric strong {
  font-size: 28px;
}

.charts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.chart-panel {
  padding: 16px;
}

.chart-panel h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

canvas {
  display: block;
  width: 100%;
  height: 260px;
}

.settings-form {
  padding: 18px;
  max-width: 720px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.settings-form button {
  grid-column: 1 / -1;
}

.account-binding-form,
.account-security-form {
  margin-top: 14px;
}

.account-binding-form h3,
.account-binding-form p,
.account-security-form h3,
.account-security-form p,
.bind-code-result {
  grid-column: 1 / -1;
}

.account-binding-form h3,
.account-security-form h3 {
  margin: 0;
  font-size: 16px;
}

.account-binding-form p,
.account-security-form p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.danger-button {
  color: var(--danger);
  border-color: #f0c6c1;
  background: #fff7f6;
  font-weight: 800;
}

.danger-button:hover {
  color: #ffffff;
  border-color: var(--danger);
  background: var(--danger);
}

.bind-code-result {
  min-height: 28px;
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 1px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(460px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: var(--radius);
  color: white;
  background: var(--ink);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
  white-space: pre-line;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1080px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .topbar,
  .topbar-actions,
  .analytics-grid,
  .charts,
  .settings-form,
  .landing-shell,
  .landing-points,
  .login-options {
    grid-template-columns: 1fr;
  }

  .login-screen {
    padding: 18px;
  }

  .landing-copy h2 {
    font-size: 28px;
  }

  .topbar {
    display: grid;
  }
}
