@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
  --c-bg: #f5f5f7;
  --c-surface: #ffffff;
  --c-border: #d8d8e0;
  --c-border-hover: #c0c0cc;
  --c-text: #1a1a2e;
  --c-text-secondary: #505065;
  --c-text-tertiary: #7a7a8e;
  --c-accent: #1a1a2e;
  --c-accent-hover: #353550;
  --c-focus: rgba(26, 26, 46, 0.12);
  --c-progress: #1a1a2e;
  --c-error: #dc2626;
  --c-success: #2d6a4f;
  --c-log-bg: #1a1a2e;
  --c-log-text: #d4d4d4;
  --c-accent-gradient: linear-gradient(135deg, #1a1a2e, #2d2d4a);
  --c-surface-gradient: linear-gradient(135deg, #ffffff, #f8f8fc);
  --c-progress-gradient: linear-gradient(90deg, #1a1a2e, #4a4a6e);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 999px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  color: var(--c-text);
  background: var(--c-bg);
  font-family: "PingFang SC", "Helvetica Neue", -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html,
body,
#app {
  min-height: 100%;
}

body {
  margin: 0;
}

* {
  box-sizing: border-box;
}

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

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--c-border);
  border-radius: var(--radius-full);
  border: 1px solid transparent;
  background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--c-border-hover);
  border: 1px solid transparent;
  background-clip: content-box;
}

::selection {
  background: rgba(26, 26, 46, 0.1);
}

.app-shell {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel {
  background: var(--c-surface-gradient);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), border-color var(--transition);
}

.panel:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--c-border-hover);
}

.topbar {
  padding: 20px 24px;
  flex: 0 0 auto;
}

.toolbar-main,
.toolbar-actions,
.workspace-header,
.task-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.toolbar-title,
.panel-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.toolbar-title strong,
.panel-title strong,
.workspace-header strong {
  font-size: 15px;
  font-weight: 500;
  color: var(--c-text);
  letter-spacing: -0.01em;
}

.toolbar-title span,
.panel-subtitle,
.subtle,
.feedback,
.empty-state {
  color: var(--c-text-secondary);
  font-size: 12px;
  font-weight: 400;
}

.credit-line {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.credit-line a {
  color: var(--c-text);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color var(--transition);
}

.credit-line a:hover {
  border-bottom-color: var(--c-text);
}

.workspace-toolbar,
.advanced-shell {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--c-border);
}

.group-title {
  display: inline-block;
  margin-bottom: 10px;
  color: var(--c-text-secondary);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.form-grid,
.advanced-grid {
  display: grid;
  gap: 12px;
}

.form-grid {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  align-items: end;
}

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

.field,
.check {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
}

.field span {
  color: var(--c-text-secondary);
  font-weight: 400;
}

.field input,
.field select,
.editor-input,
.button,
.task-item,
.segment-item {
  min-width: 0;
}

.field input,
.field select,
.editor-input {
  width: 100%;
  min-height: 36px;
  padding: 8px 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  color: var(--c-text);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.field input::placeholder,
.field select::placeholder,
.editor-input::placeholder {
  color: var(--c-text-tertiary);
}

.field input:focus,
.field select:focus,
.editor-input:focus {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px var(--c-focus), 0 1px 4px rgba(26, 26, 46, 0.06);
}

.check {
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-bg);
  cursor: pointer;
  user-select: none;
  transition: border-color var(--transition), background var(--transition);
}

.check:hover {
  border-color: var(--c-border-hover);
  background: var(--c-surface);
}

.check input {
  margin: 0;
  accent-color: var(--c-accent);
  cursor: pointer;
}

.desktop-check {
  justify-content: flex-start;
}

.wide {
  grid-column: span 2;
}

.button {
  min-height: 36px;
  padding: 0 16px;
  border: 1px solid var(--c-accent);
  border-radius: var(--radius-sm);
  background: var(--c-accent-gradient);
  color: #fff;
  cursor: pointer;
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: background var(--transition), border-color var(--transition), transform 0.1s ease, box-shadow var(--transition);
}

.button:hover {
  background: var(--c-accent-hover);
  box-shadow: 0 2px 8px rgba(26, 26, 46, 0.15);
}

.button:active {
  transform: scale(0.98);
}

.button.secondary {
  background: transparent;
  color: var(--c-text);
  border-color: var(--c-border);
}

.button.secondary:hover {
  background: var(--c-bg);
  border-color: var(--c-border-hover);
}

.button.small {
  min-height: 30px;
  padding: 0 12px;
  font-size: 12px;
}

.button:disabled {
  cursor: default;
  opacity: 0.4;
}

.status-text {
  min-height: 18px;
  margin: 12px 0 0;
}

.content-grid {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  min-height: 0;
  flex: 1 1 auto;
}

.sidebar-panel,
.workspace-panel {
  min-height: 0;
}

.sidebar-panel {
  display: flex;
  flex-direction: column;
  padding: 16px;
}

.workspace-panel {
  display: flex;
  flex-direction: column;
  padding: 20px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  padding: 0 10px;
  border-radius: var(--radius-full);
  background: var(--c-accent-gradient);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: 0 1px 4px rgba(26, 26, 46, 0.15);
}

.empty-state {
  padding: 20px 0;
  color: var(--c-text-tertiary);
}

.list-stack,
.segment-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.list-stack {
  min-height: 0;
  overflow: auto;
}

.segment-list {
  min-height: 0;
  flex: 1 1 auto;
  overflow: auto;
  padding-right: 2px;
}

.task-item,
.segment-item {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  background: var(--c-surface);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}

.task-item:hover,
.segment-item:hover {
  border-color: var(--c-border-hover);
  box-shadow: var(--shadow-sm);
}

.task-item:hover {
  background: rgba(26, 26, 46, 0.02);
}

.task-item.active {
  border-color: var(--c-accent);
  background: rgba(26, 26, 46, 0.04);
  border-left-color: var(--c-accent);
  box-shadow: inset 0 0 0 1px var(--c-accent), 0 2px 8px rgba(26, 26, 46, 0.06);
}

.task-item.completed {
  opacity: 0.85;
}

.task-item.completed::after {
  content: '';
  position: absolute;
  top: 12px;
  right: 12px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c-success);
  box-shadow: 0 0 6px rgba(45, 106, 79, 0.4);
}

.task-item.failed {
  border-color: var(--c-error);
  background: rgba(220, 38, 38, 0.03);
  opacity: 0.9;
}

.failed-footer {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
}

.failed-footer .error-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}

.retry-button {
  flex-shrink: 0;
  min-height: 26px;
  padding: 0 10px;
  border: 1px solid var(--c-error);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--c-error);
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}

.retry-button:hover {
  background: var(--c-error);
  color: #fff;
}

.task-item {
  position: relative;
  border-left: 3px solid transparent;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress {
  height: 3px;
  margin-top: 8px;
  background: var(--c-border);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--c-progress-gradient);
  border-radius: var(--radius-full);
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.error-text {
  margin: 8px 0 0;
  color: var(--c-error);
  font-size: 12px;
}

.export-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.source-text {
  margin: 10px 0;
  padding: 10px 12px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
  color: var(--c-text);
  line-height: 1.6;
  background: var(--c-bg);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--c-border);
}

.editor-input {
  min-height: 64px;
  resize: vertical;
  line-height: 1.5;
}

.editor-input:disabled {
  background: var(--c-bg);
  cursor: not-allowed;
  opacity: 0.6;
}

.log-drawer {
  margin-top: 16px;
  border-top: 1px solid var(--c-border);
  padding-top: 16px;
}

.log-toggle {
  width: 100%;
  min-height: 38px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  background: var(--c-surface-gradient);
  color: var(--c-text);
  cursor: pointer;
  font-weight: 500;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}

.log-toggle:hover {
  border-color: var(--c-border-hover);
  background: var(--c-bg);
  box-shadow: var(--shadow-sm);
}

.log-panel {
  margin-top: 10px;
}

.log-list {
  max-height: 220px;
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  background: var(--c-log-bg);
}

.log-line {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  line-height: 1.6;
  color: var(--c-log-text);
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
}

.log-line + .log-line {
  margin-top: 2px;
}

.segment-id {
  color: var(--c-text-tertiary);
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 11px;
}

.log-chevron {
  font-size: 14px;
  font-weight: 300;
  color: var(--c-text-secondary);
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.toggle-button {
  font-size: 12px;
}

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

.task-item strong {
  font-weight: 500;
  font-size: 13px;
}

.task-item .subtle {
  margin-top: 2px;
}

.task-item .status-active {
  color: var(--c-accent);
  font-weight: 600;
  position: relative;
}

.segment-item {
  border-left: 3px solid transparent;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
  position: relative;
}

.segment-item:hover {
  border-left-color: var(--c-accent);
  background: rgba(26, 26, 46, 0.02);
  box-shadow: var(--shadow-sm);
}

.segment-item:focus-within {
  border-left-color: var(--c-accent);
  background: rgba(26, 26, 46, 0.03);
  box-shadow: 0 0 0 1px rgba(26, 26, 46, 0.08);
}

.segment-item .task-row {
  margin-bottom: 4px;
}

@media (max-width: 1360px) {
  .content-grid {
    grid-template-columns: 280px minmax(0, 1fr);
  }

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

  .advanced-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }

  .wide {
    grid-column: span 1;
  }
}
