:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #52616f;
  --line: #d9dee7;
  --line-strong: #b8c2cc;
  --sidebar: #102033;
  --sidebar-active: #1c6dd0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success-bg: #e8f5ee;
  --success-text: #12643f;
  --warning-bg: #fff4df;
  --warning-text: #8a4b00;
  --error-bg: #fdecec;
  --error-text: #9f1d1d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  color: #fff;
  min-height: 100vh;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand,
.auth-brand {
  font-weight: 700;
  letter-spacing: 0;
}

.brand {
  margin-bottom: 6px;
}

.sidebar nav {
  display: grid;
  gap: 4px;
}

.sidebar a {
  color: #d9e8ff;
  display: block;
  padding: 10px 12px;
  border-radius: 6px;
  text-decoration: none;
}

.sidebar a:hover,
.sidebar a.active {
  background: var(--sidebar-active);
  color: #fff;
}

.logout-form {
  margin-top: auto;
}

.content {
  padding: 24px;
  max-width: 1280px;
  width: 100%;
}

.auth-body {
  display: block;
  min-height: 100vh;
  background: var(--bg);
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(100%, 420px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 14px 36px rgba(18, 32, 51, 0.12);
}

.auth-brand {
  margin-bottom: 20px;
  color: var(--muted);
}

h1,
h2 {
  line-height: 1.2;
}

h1 {
  margin: 0 0 18px;
}

h1 span {
  color: var(--muted);
  font-size: 18px;
}

h2 {
  margin: 0 0 12px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin: 16px 0;
}

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

.form-row {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
}

label {
  display: block;
  margin: 10px 0;
  color: var(--muted);
  font-size: 14px;
}

label.inline {
  display: flex;
  gap: 8px;
  align-items: center;
}

input,
select,
button {
  font: inherit;
  min-height: 40px;
  padding: 9px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
}

input,
select {
  width: 100%;
  background: #fff;
  color: var(--text);
}

input[type="hidden"] {
  display: none;
}

input[type="checkbox"] {
  width: auto;
  min-height: auto;
}

.form-row input,
.form-row select {
  width: auto;
  min-width: 180px;
}

button,
.button-link {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button:hover,
.button-link:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.secondary-button {
  width: 100%;
  background: transparent;
  border-color: rgba(217, 232, 255, 0.45);
  color: #d9e8ff;
}

.secondary-button:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(217, 232, 255, 0.8);
}

.auth-form {
  display: grid;
  gap: 10px;
}

.notice {
  border-radius: 6px;
  padding: 12px;
  margin: 12px 0;
  overflow-wrap: anywhere;
}

.notice.warning {
  background: var(--warning-bg);
  color: var(--warning-text);
  border: 1px solid #ffd99d;
}

.notice.error {
  background: var(--error-bg);
  color: var(--error-text);
  border: 1px solid #f5b5b5;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  overflow-wrap: anywhere;
}

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

th {
  background: #eef2f6;
  color: #334155;
}

code,
small {
  overflow-wrap: anywhere;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.stats div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.stats span {
  display: block;
  font-size: 30px;
  font-weight: 700;
}

.stats label {
  margin: 0;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef2f6;
  color: #334155;
  font-size: 13px;
  font-weight: 700;
}

.status-configured,
.status-done,
.status-success {
  background: var(--success-bg);
  color: var(--success-text);
}

.status-failed,
.status-error {
  background: var(--error-bg);
  color: var(--error-text);
}

.status-running,
.status-queued,
.status-not_configured {
  background: var(--warning-bg);
  color: var(--warning-text);
}

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

  .sidebar {
    min-height: auto;
  }

  .content {
    padding: 16px;
  }

  table {
    display: block;
    overflow-x: auto;
  }

  .form-row input,
  .form-row select,
  .form-row button {
    width: 100%;
  }
}

/* Table Sorter Styles */
th { cursor: pointer; user-select: none; }
th:hover { background-color: #f0f0f0; }

/* Logs Viewer Styles */
.log-container {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 1rem;
  border-radius: 8px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.9rem;
  height: 70vh;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.log-container .error {
  color: #f44747;
  font-weight: bold;
}
.log-container .info {
  color: #569cd6;
}
.log-container .warning {
  color: #d7ba7d;
}

/* Chat Viewer Styles */
.message-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  max-width: 800px;
  margin: 0 auto;
  background: #f9f9f9;
  border-radius: 8px;
  height: 70vh;
  overflow-y: auto;
}
.msg {
  padding: 0.8rem;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  max-width: 80%;
}
.msg.out {
  align-self: flex-end;
  background: #dcf8c6;
}
.msg.in {
  align-self: flex-start;
}
.msg-header {
  font-size: 0.8rem;
  color: #666;
  margin-bottom: 0.4rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}
.msg-text {
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-deleted {
  color: #999;
  font-style: italic;
}
.att {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: #0066cc;
}
