@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&display=swap');

[data-theme="light"] {
  --bg: #f4f4f5;
  --bg-card: #ffffff;
  --text: #18181b;
  --text-muted: #71717a;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --border: #e4e4e7;
  --input-bg: #ffffff;
  --input-border: #d4d4d8;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.1);
  --error: #dc2626;
  --success: #16a34a;
  --radius: 10px;
  --radius-sm: 6px;
}

[data-theme="dark"] {
  --bg: #0f0f12;
  --bg-card: #18181b;
  --text: #fafafa;
  --text-muted: #a1a1aa;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --border: #27272a;
  --input-bg: #27272a;
  --input-border: #3f3f46;
  --shadow: 0 1px 3px rgba(0,0,0,.3);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.4);
  --error: #ef4444;
  --success: #22c55e;
  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Manrope', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  line-height: 1.5;
  transition: background .2s, color .2s;
  overflow-x: hidden;
}

.app-wrap {
  width: 100%;
  max-width: var(--app-max-width, 100%);
  margin: 0 auto;
  padding: 1rem clamp(0.75rem, 4vw, 1.5rem);
  padding-top: calc(1rem + 52px);
  min-width: 0;
}

header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.625rem clamp(0.75rem, 4vw, 1rem);
  margin-bottom: 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
header .header-inner {
  width: 100%;
  max-width: var(--app-max-width, 100%);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  min-width: 0;
  padding: 0 0.25rem;
}

@media (min-width: 640px) {
  :root { --app-max-width: 640px; }
  .app-wrap { padding-top: calc(1.25rem + 52px); }
}

@media (min-width: 768px) {
  :root { --app-max-width: 720px; }
  .app-wrap { padding: 1.5rem 1.5rem; padding-top: calc(1.5rem + 52px); }
  header { padding: 0.75rem 1rem; }
  header .header-inner { padding: 0; }
}

@media (min-width: 1024px) {
  :root { --app-max-width: 900px; }
  .app-wrap { padding: 1.5rem 2rem; padding-top: calc(1.5rem + 56px); }
}

header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

header nav { margin-bottom: 0; }

.theme-toggle {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  transition: background .15s, border-color .15s, transform .1s;
  flex-shrink: 0;
}
.theme-toggle:hover { background: var(--input-bg); border-color: var(--input-border); }
.theme-toggle:active { transform: scale(0.96); }

nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

header nav { margin-bottom: 0; }
nav a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  font-size: clamp(0.8125rem, 2vw, 0.9375rem);
  padding: 0.5rem 0.625rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
@media (min-width: 768px) {
  nav a { padding: 0.5rem 0.75rem; }
}
nav a:hover { background: var(--input-bg); border-color: var(--input-border); color: var(--accent); }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(1rem, 4vw, 1.25rem);
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
  transition: box-shadow .2s, border-color .2s;
  min-width: 0;
}
.card:hover { box-shadow: var(--shadow-lg); }
.card small, .card .muted { color: var(--text-muted); font-size: 0.875rem; }

form label {
  display: block;
  margin-top: 1rem;
  font-weight: 500;
  font-size: 0.9375rem;
  color: var(--text);
}
form label:first-of-type { margin-top: 0; }

input, textarea, select {
  width: 100%;
  padding: 0.625rem 0.875rem;
  margin-top: 0.375rem;
  font: inherit;
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }
input:disabled, select:disabled { opacity: 0.7; cursor: not-allowed; }

textarea { min-height: 80px; resize: vertical; }

.input-row { display: flex; gap: 0.5rem; align-items: flex-end; flex-wrap: wrap; }
.input-row input { flex: 1; min-width: 0; }
.input-row button { flex-shrink: 0; }
.attach-row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.attach-row select { flex: 1; min-width: 200px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.625rem 1.25rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.9375rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--accent);
  color: #fff;
  margin-top: 1.25rem;
  margin-right: 0.5rem;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  margin-top: 1.25rem;
  margin-right: 0.5rem;
}
.btn-secondary:hover { background: var(--border); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8125rem; margin-top: 0; }

.msg { margin-top: 1rem; font-size: 0.9375rem; }
.msg.error { color: var(--error); }
.msg.success { color: var(--success); }

.links { margin-top: 1.5rem; font-size: 0.9375rem; }
.links a { color: var(--accent); text-decoration: none; font-weight: 500; }
.links a:hover { text-decoration: underline; }
.links span { color: var(--text-muted); margin: 0 0.5rem; }

table {
  width: 100%;
  min-width: 280px;
  border-collapse: collapse;
  margin-top: 0.5rem;
  font-size: clamp(0.8125rem, 2vw, 0.9375rem);
}
th, td {
  padding: 0.5rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  word-break: break-word;
}
@media (min-width: 768px) {
  th, td { padding: 0.75rem 1rem; }
}
th { font-weight: 600; color: var(--text-muted); background: var(--bg); white-space: nowrap; }
tr:hover td { background: var(--input-bg); }
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
}

.section-title { font-size: 1.125rem; font-weight: 600; margin: 1.5rem 0 0.75rem; }
.section-title:first-of-type { margin-top: 0; }

.result-box {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  border: 1px solid var(--border);
  font-size: 0.9375rem;
}
.result-box a { color: var(--accent); }
.result-box img { margin-top: 0.5rem; display: block; }
