:root {
  --blue: #1c05b8;
  --blue-dark: #110073;
  --ink: #14151f;
  --muted: #687083;
  --line: #dfe4ed;
  --bg: #f4f6fa;
  --panel: #ffffff;
  --green: #2d7d22;
  --red: #e61d1d;
  --yellow: #fff200;
  --soft-blue: #dce9ff;
}

@media (max-width: 768px) {
  :root {
    --bg: #eef2f8;
  }

  body {
    background: var(--bg);
  }

  .menu-toggle {
    top: 10px;
    left: 10px;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    box-shadow: 0 8px 16px rgba(12, 18, 33, 0.35);
  }

  .sidebar {
    width: 86vw;
    max-width: 320px;
    padding: 14px 12px 18px;
    gap: 16px;
    box-shadow: 18px 0 40px rgba(15, 23, 42, 0.45);
    border-right: 1px solid rgba(255, 255, 255, 0.14);
    background: linear-gradient(180deg, #1604ad 0%, #0f0285 100%);
  }

  .brand {
    min-height: 54px;
    justify-content: start;
  }

  .brand img {
    width: 126px;
  }

  .nav-item {
    border-radius: 10px;
    padding: 12px 11px;
    font-size: 1rem;
    font-weight: 800;
    color: rgba(255, 255, 255, 0.9);
    border: 1px solid transparent;
  }

  .nav-item.active,
  .nav-item:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateX(2px);
  }

  main {
    max-width: none;
    padding: 62px 8px 14px;
  }

  .topbar {
    padding: 12px;
    border-radius: 12px;
    margin-bottom: 10px;
    gap: 10px;
    border-color: #d7deea;
    background: #fff;
    border: 2px solid #d4def2;
    box-shadow: 0 10px 24px rgba(16, 24, 40, 0.09);
  }

  .topbar-title {
    width: 100%;
  }

  .topbar-title .eyebrow {
    margin-bottom: 2px;
    font-size: 0.68rem;
    color: #5c6679;
  }

  h1 {
    font-size: 1.42rem;
    line-height: 1.12;
    color: #0f172a;
    font-weight: 900;
  }

  .mobile-status {
    display: block;
    color: #445069;
    font-size: 0.74rem;
  }

  .session-chip {
    width: 100%;
    border-radius: 12px;
    padding: 8px;
    gap: 8px;
    background: #f1f5fb;
    border-color: #d8e0ee;
  }

  .actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .actions button,
  .session-chip .small-btn,
  .compact-actions button,
  .history-actions button,
  .section-title button,
  .primary,
  .secondary,
  .ghost,
  .danger {
    width: 100%;
    min-height: 42px;
    border-radius: 10px;
  }

  .panel {
    border-radius: 12px;
    padding: 12px;
  }

  .field-grid,
  .metric-grid,
  .permissions-box {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }

  .tip-tools {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    align-items: center;
    gap: 8px;
  }

  .history-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .history-item small {
    display: block;
    margin-top: 2px;
    font-size: 0.78rem;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: 270px;
  padding: 24px 16px;
  background: var(--blue);
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 28px;
  z-index: 60;
  transform: translateX(-100%);
  transition: transform 0.22s ease;
}

body.menu-open .sidebar {
  transform: translateX(0);
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: none;
  place-items: center;
  padding: 18px;
  background: #ffffff;
}

body.auth-locked .auth-screen {
  display: grid;
}

.auth-card {
  width: min(420px, 100%);
  border: 1px solid rgba(9, 43, 118, 0.2);
  border-radius: 12px;
  padding: 18px;
  background: #1c4fd7;
  box-shadow: 0 24px 50px rgba(9, 43, 118, 0.3);
}

.auth-card h2 {
  margin-bottom: 8px;
  color: #ffffff;
}

.auth-card p {
  margin: 0 0 14px;
  color: rgba(255, 255, 255, 0.82);
}

.auth-card label {
  color: rgba(255, 255, 255, 0.9);
}

.auth-card button {
  width: 100%;
  margin-top: 8px;
}

.auth-brand {
  min-height: 72px;
  margin-bottom: 8px;
  background: transparent;
}

.auth-brand img {
  width: min(210px, 90%);
  filter: brightness(0) invert(1);
  opacity: 1;
}

.menu-toggle {
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: 80;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  color: #fff;
  background: var(--ink);
  font-size: 1.2rem;
  line-height: 1;
}

.menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 24, 0.42);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

body.menu-open .menu-backdrop {
  opacity: 1;
  pointer-events: auto;
}

.brand {
  min-height: 120px;
  display: grid;
  place-items: center;
  border-radius: 8px;
}

.brand img {
  width: min(218px, 92%);
  height: auto;
  display: block;
}

nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  border: 0;
  border-radius: 8px;
  padding: 12px 14px;
  text-align: left;
  color: rgba(255, 255, 255, 0.76);
  background: transparent;
  cursor: pointer;
}

.nav-item.active,
.nav-item:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
}

main {
  min-width: 0;
  max-width: 1220px;
  margin: 0 auto;
  padding: 82px 22px 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 18px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 14px 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.mobile-status {
  display: none;
  margin: 6px 0 0;
  color: #5f6b80;
  font-size: 0.78rem;
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(1.9rem, 3vw, 2.7rem);
}

h2 {
  font-size: 1rem;
}

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

.session-chip {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: #f8fafc;
}

.session-chip small {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.session-chip strong {
  font-size: 0.88rem;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 11px 14px;
  font-weight: 800;
  cursor: pointer;
}

.primary {
  color: #fff;
  background: var(--blue);
}

.secondary {
  color: #fff;
  background: var(--ink);
}

.ghost {
  color: var(--ink);
  background: #e8ecf4;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.layout {
  display: grid;
  gap: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 14px 34px rgba(16, 24, 40, 0.06);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(28, 5, 184, 0.12);
}

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

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

@media (max-width: 960px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f8fafc;
}

.metric small {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
}

.metric strong {
  font-size: 1.25rem;
}

.metric.total {
  color: #fff;
  border-color: var(--blue);
  background: var(--blue);
}

.metric.total small {
  color: rgba(255, 255, 255, 0.78);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

th {
  color: #fff;
  background: var(--ink);
  font-size: 0.75rem;
  text-transform: uppercase;
}

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

td input {
  border: 0;
  border-radius: 0;
  padding: 7px 6px;
  box-shadow: none;
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  color: #fff;
  background: var(--green);
}

.icon-btn.danger {
  background: var(--red);
}

.icon-btn.tip {
  background: var(--blue);
}

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

.tip-tools {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 12px;
  background: #f8fafc;
}

.tip-tools span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.tip-tools strong {
  min-width: 24px;
  text-align: center;
}

.small-btn {
  min-height: 38px;
  padding: 8px 10px;
  white-space: nowrap;
}

.remove-row {
  width: 32px;
  height: 32px;
  padding: 0;
  color: var(--red);
  background: #ffe8e8;
}

.tips-table {
  min-width: 700px;
  table-layout: fixed;
}

.tips-table th:not(:first-child),
.tips-table td:not(:first-child) {
  text-align: right;
}

.tips-table td:first-child {
  width: 170px;
}

.tips-table th:not(:first-child):not(:last-child),
.tips-table td:not(:first-child):not(:last-child) {
  width: 112px;
}

.tips-table input {
  text-align: right;
}

.tips-table td:first-child input {
  text-align: left;
}

.row-total {
  color: var(--blue);
  font-weight: 900;
  white-space: nowrap;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  background: #fbfcff;
}

.history-item strong {
  display: block;
}

.history-item small {
  color: var(--muted);
}

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

button.danger {
  color: #fff;
  background: var(--red);
  border-color: transparent;
}

.oath-panel {
  border-color: rgba(28, 5, 184, 0.28);
  background: #f8f7ff;
}

.oath-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  color: var(--ink);
  font-size: 0.93rem;
  font-weight: 700;
  line-height: 1.45;
  text-transform: none;
}

.oath-check input {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  margin-top: 2px;
}

.user-grid {
  margin-bottom: 14px;
}

.role-pill {
  display: inline-flex;
  border-radius: 999px;
  padding: 5px 9px;
  color: #fff;
  background: var(--blue);
  font-size: 0.75rem;
  font-weight: 900;
  text-transform: uppercase;
}

.permissions-box {
  margin: 8px 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8fafc;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.permissions-box strong {
  grid-column: 1 / -1;
}

.permissions-box label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: none;
}

.permissions-box input {
  width: 16px;
  height: 16px;
}

.drive-panel {
  max-width: 880px;
  margin-bottom: 16px;
}

.drive-panel p {
  color: var(--muted);
  margin-top: 0;
  margin-bottom: 12px;
}

.integration-grid {
  margin-bottom: 14px;
}

.script-box {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.script-box strong {
  display: block;
  padding: 12px 14px;
  background: var(--soft-blue);
}

pre {
  margin: 0;
  padding: 14px;
  overflow: auto;
  color: #eff5ff;
  background: #111827;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100vw - 44px));
  border-radius: 8px;
  padding: 13px 15px;
  color: #fff;
  background: var(--ink);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.2);
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 960px) {
  body {
    font-size: 15px;
  }

  .sidebar {
    width: min(88vw, 280px);
    padding: 18px 14px;
  }

  .brand {
    min-height: 64px;
    justify-content: start;
  }

  .brand img {
    width: 132px;
  }

  .topbar,
  .history-item {
    align-items: stretch;
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .actions {
    justify-content: stretch;
    width: 100%;
  }

  .actions button {
    flex: 1 1 100%;
    width: 100%;
  }

  .field-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  main {
    padding: 74px 14px 16px;
  }

  .panel {
    padding: 12px;
  }

  .session-chip {
    width: 100%;
  }

  .session-chip .small-btn {
    flex: 1 1 160px;
  }

  .table-wrap {
    margin: 0 -2px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 560px;
  }

  .tips-table {
    min-width: 600px;
  }

  .history-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 14px;
  }

  main {
    padding: 70px 10px 14px;
  }

  .menu-toggle {
    top: 12px;
    left: 12px;
  }

  h1 {
    font-size: clamp(1.6rem, 7vw, 2rem);
  }

  .auth-screen {
    padding: 12px;
  }

  .auth-card {
    width: 100%;
    max-width: 380px;
    padding: 12px;
  }

  .section-title {
    gap: 8px;
  }

  .section-title > div {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .session-chip {
    gap: 8px;
    padding: 8px;
  }

  .session-chip .small-btn,
  .compact-actions button,
  .history-actions button,
  .section-title button,
  .primary,
  .secondary,
  .ghost {
    width: 100%;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
  }

  .tip-tools {
    width: 100%;
    justify-content: space-between;
  }

  .tip-tools .small-btn {
    min-width: 42px;
    text-align: center;
  }

  .toast {
    right: 12px;
    left: 12px;
    bottom: 12px;
    max-width: none;
  }

  table {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0 8px;
  }

  table thead {
    display: none;
  }

  table tbody,
  table tr,
  table td {
    display: block;
    width: 100%;
  }

  table tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
  }

  table td {
    border: 0;
    border-bottom: 1px solid #eef2f7;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    text-align: left;
  }

  table td:last-child {
    border-bottom: 0;
  }

  table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0;
    flex: 0 0 44%;
  }

  table td input {
    width: 56%;
    text-align: right;
    padding: 8px;
  }

  .tips-table td:first-child input,
  table td:first-child input {
    text-align: left;
  }

  .row-total {
    justify-content: space-between;
  }
}
