:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: rgba(79, 70, 229, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.1);
  --success: #059669;
  --success-soft: rgba(5, 150, 105, 0.12);
  --warn: #d97706;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
  --font: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 10% -10%, rgba(79, 70, 229, 0.14), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(14, 165, 233, 0.1), transparent 50%),
    var(--bg);
  color: var(--text);
  line-height: 1.5;
}

code {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.9em;
  background: var(--surface-2);
  padding: 0.12em 0.35em;
  border-radius: 6px;
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  padding: 1.75rem 1.25rem;
  border-right: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.brand {
  display: flex;
  gap: 0.85rem;
  align-items: center;
}

.brand-mark {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--accent), #6366f1 45%, #0ea5e9);
  box-shadow: 0 10px 25px rgba(79, 70, 229, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.brand-mark-icon {
  width: 22px;
  height: 22px;
  display: block;
}

.brand-title {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.brand-sub {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.1rem;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nav-link {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.6rem;
  padding: 0.65rem 0.75rem;
  min-height: 44px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.nav-link:hover {
  background: var(--surface-2);
}

.nav-link.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-ico {
  opacity: 0.75;
  font-size: 0.95rem;
}

.sidebar-user {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.sidebar-user-name {
  font-weight: 600;
  font-size: 0.88rem;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-logout {
  flex-shrink: 0;
  min-height: 40px;
  width: auto;
}

.sidebar-hint {
  margin: auto 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.45;
}

.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(1rem, env(safe-area-inset-top, 0px)) max(1rem, env(safe-area-inset-right, 0px))
    max(1rem, env(safe-area-inset-bottom, 0px)) max(1rem, env(safe-area-inset-left, 0px));
  background: radial-gradient(1200px 600px at 10% -10%, rgba(79, 70, 229, 0.14), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(14, 165, 233, 0.1), transparent 50%), var(--bg);
}

.login-card {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
}

.login-brand {
  display: flex;
  gap: 0.85rem;
  align-items: center;
  margin-bottom: 1.25rem;
}

.login-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.login-sub {
  margin: 0.15rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.login-alert {
  font-size: 0.88rem;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--text);
  margin-bottom: 1rem;
  line-height: 1.45;
}

.login-alert code {
  font-size: 0.82em;
}

.login-alert-err {
  background: var(--danger-soft);
  color: var(--danger);
}

.field-row {
  flex-direction: row;
  align-items: center;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
}

.checkbox-label input {
  width: auto;
  min-height: auto;
  accent-color: var(--accent);
}

.main {
  padding: 2rem 2.25rem 3rem;
  max-width: 1120px;
}

.page-head {
  margin-bottom: 1.75rem;
}

.page-title {
  margin: 0 0 0.35rem;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.page-lead {
  margin: 0;
  max-width: 62ch;
  color: var(--muted);
  font-size: 1rem;
}

.grid-2 {
  display: grid;
  gap: 1.25rem;
}

@media (min-width: 960px) {
  .grid-2 {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.35rem 1.4rem;
  box-shadow: var(--shadow);
  border: 1px solid rgba(226, 232, 240, 0.9);
}

.card-muted {
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.card-title {
  margin: 0 0 1.1rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.field-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.field-hint-warn {
  color: var(--warn);
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.dur-row > div {
  position: relative;
}

.suffix-label {
  position: absolute;
  right: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.8rem;
  color: var(--muted);
  pointer-events: none;
}

.dur-row .input {
  padding-right: 2.25rem;
}

.input {
  width: 100%;
  max-width: 100%;
  padding: 0.75rem 0.85rem;
  min-height: 48px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font: inherit;
  font-size: 1rem;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

select.input {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

.form-actions {
  margin-top: 0.25rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.1rem;
  min-height: 48px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  background: var(--surface-2);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: none;
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
}

.btn-danger:hover {
  background: rgba(220, 38, 38, 0.18);
}

.btn-sm {
  padding: 0.5rem 0.75rem;
  min-height: 40px;
  font-size: 0.9rem;
}

.btn-spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.empty-state {
  color: var(--muted);
  font-size: 0.95rem;
 padding: 0.5rem 0;
}

.result-panel {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.result-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  width: fit-content;
}

.result-badge.ok {
  background: var(--success-soft);
  color: var(--success);
}

.result-badge.err {
  background: var(--danger-soft);
  color: var(--danger);
}

.step-list {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--text);
}

.step-list li {
  margin-bottom: 0.35rem;
}

.mono {
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
}

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

.table-wrap {
  overflow-x: auto;
  margin: 0 -0.25rem;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table th,
.table td {
  text-align: left;
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.table th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.webhook-cell {
  max-width: 280px;
  word-break: break-all;
  color: var(--muted);
  font-size: 0.82rem;
}

.actions-cell {
  white-space: nowrap;
  text-align: right;
}

.dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  box-shadow: var(--shadow);
  max-width: min(440px, calc(100vw - 2rem));
}

.dialog::backdrop {
  background: rgba(15, 23, 42, 0.35);
  backdrop-filter: blur(4px);
}

.dialog .form {
  padding: 1.35rem 1.4rem;
}

.dialog-title {
  margin: 0 0 1rem;
  font-size: 1.1rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.toast {
  position: fixed;
  bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  right: max(1rem, env(safe-area-inset-right, 0px));
  left: auto;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  max-width: min(360px, calc(100vw - 2rem));
  z-index: 50;
}

.toast.is-error {
  background: var(--danger);
}

.toast.is-ok {
  background: var(--success);
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
    padding: max(1rem, env(safe-area-inset-top, 0px)) max(1rem, env(safe-area-inset-right, 0px)) 1rem max(1rem, env(safe-area-inset-left, 0px));
    border-right: none;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
  }

  .brand {
    flex-shrink: 0;
  }

  .nav {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(108px, 1fr));
    gap: 0.5rem;
    width: 100%;
  }

  .nav-link {
    flex: 1;
    justify-content: center;
    text-align: center;
    font-size: 0.88rem;
    padding: 0.75rem 0.5rem;
  }

  .sidebar-hint {
    display: none;
  }

  .main {
    padding: 1rem max(1rem, env(safe-area-inset-right, 0px)) max(1.5rem, env(safe-area-inset-bottom, 0px)) max(1rem, env(safe-area-inset-left, 0px));
    max-width: none;
  }

  .page-title {
    font-size: 1.4rem;
  }

  .page-lead {
    font-size: 0.92rem;
  }

  .card {
    padding: 1.15rem 1rem;
  }

  .row-2 {
    gap: 0.5rem;
  }

  .webhook-cell {
    max-width: none;
  }

  .actions-cell {
    white-space: normal;
  }

  .actions-cell .btn {
    display: inline-flex;
    width: auto;
    margin-bottom: 0.35rem;
  }

  .actions-cell .btn:last-child {
    margin-bottom: 0;
  }

  .table th,
  .table td {
    padding: 0.55rem 0.35rem;
    font-size: 0.85rem;
  }

  .dialog {
    width: calc(100vw - 1.5rem);
    max-width: none;
    margin: auto;
  }

  .toast {
    right: max(0.75rem, env(safe-area-inset-right, 0px));
    left: max(0.75rem, env(safe-area-inset-left, 0px));
    max-width: none;
    width: auto;
    text-align: center;
    box-sizing: border-box;
  }
}

@media (max-width: 380px) {
  .nav-link {
    font-size: 0.8rem;
    flex-direction: column;
    gap: 0.2rem;
    min-height: 52px;
  }

  .nav-ico {
    font-size: 1.1rem;
  }
}
