.hidden {
  display: none !important;
}

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1c1c1c;
  --muted: #6b6b6b;
  --border: #e2e2df;
  --accent: #2f5d50;
  --accent-soft: #e6efec;
  --danger: #b8482f;
  font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --surface: #1f2123;
    --text: #ececec;
    --muted: #9b9b9b;
    --border: #333537;
    --accent: #7fc9b3;
    --accent-soft: #22332e;
    --danger: #d97a5f;
  }
}

:root[data-theme="light"] {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1c1c1c;
  --muted: #6b6b6b;
  --border: #e2e2df;
  --accent: #2f5d50;
  --accent-soft: #e6efec;
  --danger: #b8482f;
}

:root[data-theme="dark"] {
  --bg: #17181a;
  --surface: #1f2123;
  --text: #ececec;
  --muted: #9b9b9b;
  --border: #333537;
  --accent: #7fc9b3;
  --accent-soft: #22332e;
  --danger: #d97a5f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.2rem 1.5rem 3rem;
}

a {
  color: var(--accent);
}

h1, h2, h3, h4 {
  font-weight: 600;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

input, select, textarea {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
}

textarea {
  resize: vertical;
}

button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.9rem;
}

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

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

th, td {
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

tr:last-child td {
  border-bottom: none;
}

pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  font-size: 0.85rem;
}

.diff-view {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow-x: auto;
  font-size: 0.85rem;
}

.diff-line {
  padding: 0.05rem 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.diff-line.add {
  background: color-mix(in srgb, #2f7d4f 8%, transparent);
  color: #1c1c1c;
}

.diff-line.remove {
  background: color-mix(in srgb, #b8482f 8%, transparent);
  color: #1c1c1c;
}

.diff-char {
  border-radius: 3px;
  font-weight: 700;
  color: #ffffff;
  padding: 0 0.05rem;
}

.diff-line.add .diff-char {
  background: #2f7d4f;
}

.diff-line.remove .diff-char {
  background: #b8482f;
}

@media (prefers-color-scheme: dark) {
  .diff-line.add {
    background: color-mix(in srgb, #5fbf82 10%, transparent);
    color: #ececec;
  }
  .diff-line.remove {
    background: color-mix(in srgb, #d97a5f 10%, transparent);
    color: #ececec;
  }
  .diff-line.add .diff-char {
    background: #5fbf82;
    color: #0e1a14;
  }
  .diff-line.remove .diff-char {
    background: #d97a5f;
    color: #1a0e0a;
  }
}

:root[data-theme="dark"] .diff-line.add {
  background: color-mix(in srgb, #5fbf82 10%, transparent);
  color: #ececec;
}

:root[data-theme="dark"] .diff-line.remove {
  background: color-mix(in srgb, #d97a5f 10%, transparent);
  color: #ececec;
}

:root[data-theme="dark"] .diff-line.add .diff-char {
  background: #5fbf82;
  color: #0e1a14;
}

:root[data-theme="dark"] .diff-line.remove .diff-char {
  background: #d97a5f;
  color: #1a0e0a;
}

:root[data-theme="light"] .diff-line.add {
  background: color-mix(in srgb, #2f7d4f 8%, transparent);
  color: #1c1c1c;
}

:root[data-theme="light"] .diff-line.remove {
  background: color-mix(in srgb, #b8482f 8%, transparent);
  color: #1c1c1c;
}

:root[data-theme="light"] .diff-line.add .diff-char {
  background: #2f7d4f;
  color: #ffffff;
}

:root[data-theme="light"] .diff-line.remove .diff-char {
  background: #b8482f;
  color: #ffffff;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.md-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1.2rem;
  min-height: 300px;
  overflow-x: auto;
}

.md-preview :is(h1, h2, h3, h4, h5, h6) {
  margin: 0.6rem 0 0.4rem;
}

.md-preview p {
  margin: 0.5rem 0;
}

.md-preview blockquote {
  margin: 0.5rem 0;
  padding: 0.3rem 0.9rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

.md-preview pre {
  margin: 0.5rem 0;
}

.md-preview code {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.md-preview pre code {
  background: none;
  color: inherit;
  padding: 0;
}

.field {
  margin-bottom: 1rem;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.help-wrap {
  position: relative;
  display: inline-block;
}

.help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 1.1rem;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1;
  cursor: help;
  margin-left: 0.3rem;
}

.help-icon:hover,
.help-icon:focus {
  border-color: var(--accent);
  color: var(--accent);
}

.help-tooltip {
  display: none;
  position: absolute;
  top: 140%;
  left: 0;
  z-index: 20;
  width: 20rem;
  max-width: 70vw;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  font-size: 0.8rem;
  font-weight: normal;
  line-height: 1.4;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
  white-space: normal;
}

.help-wrap:hover .help-tooltip,
.help-wrap.open .help-tooltip {
  display: block;
}

input:disabled,
select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

[role="group"] input,
[role="group"] select {
  width: auto;
  flex: 1;
}

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

[role="group"] {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.app-header a {
  text-decoration: none;
  color: var(--text);
}

.app-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.app-controls select,
.app-controls button {
  width: auto;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.tool-card {
  display: block;
  padding: 1.25rem;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  text-decoration: none;
  color: inherit;
}

.tool-card:hover {
  border-color: var(--accent);
}

.tool-card h3 {
  margin: 0 0 0.25rem;
  color: var(--text);
}

.tool-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

/* --- Sidebar --- */
:root {
  --sidebar-width: 220px;
  --sidebar-width-collapsed: 56px;
}

app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  z-index: 10;
  transition: width 0.15s ease;
}

body.sidebar-collapsed app-sidebar {
  width: var(--sidebar-width-collapsed);
}

.sidebar-toggle {
  border: none;
  background: none;
  color: var(--muted);
  align-self: flex-end;
  padding: 0.8rem 0.9rem;
  font-size: 1rem;
  cursor: pointer;
  border-radius: 0;
}

.sidebar-toggle:hover {
  color: var(--accent);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 0 0.5rem 1rem;
  gap: 0.15rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.6rem;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  white-space: nowrap;
  font-size: 0.9rem;
}

.sidebar-link:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.sidebar-link.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
  width: 1.4rem;
  text-align: center;
}

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

body.sidebar-collapsed .sidebar-label {
  display: none;
}

body.has-sidebar .container {
  margin-left: var(--sidebar-width);
  transition: margin-left 0.15s ease;
}

body.has-sidebar.sidebar-collapsed .container {
  margin-left: var(--sidebar-width-collapsed);
}

