:root {
  color-scheme: dark;
  --window-bg: #232323;
  --grid-bg: #292929;
  --grid-alt-bg: #262626;
  --grid-hover-bg: #2d292c;
  --header-bg: #1f1f1f;
  --line-soft: #383838;
  --text-primary: #f9f9f9;
  --text-muted: #d0d0d0;
  --text-dim: #888888;
  --text-active: #8ed6a6;
  --text-available: #e6e8e6;
  --bar-bg: #656565;
  --bar-active: #98d2ec;
  --bar-good: #92d2b1;
  --bar-warn: #ddcc98;
  --bar-low: #daa5a0;
  --control-bg: #424956;
  --control-border: #586272;
  --control-disabled: #3c3e42;
  --focus: #98d2ec;
  --radius-sm: 4px;
  --radius-md: 6px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --row-height: 86px;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--window-bg);
  color: var(--text-primary);
  font-size: 12px;
}

button {
  font: inherit;
}

.is-hidden {
  display: none !important;
}

.login-panel {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: var(--space-4);
}

.login-box {
  display: grid;
  width: min(360px, 100%);
  gap: var(--space-3);
  border: 1px solid var(--line-soft);
  background: var(--grid-bg);
  padding: var(--space-5);
}

.login-box label {
  display: grid;
  gap: var(--space-2);
  color: var(--text-muted);
}

.login-box input {
  height: 34px;
  border: 1px solid var(--control-border);
  border-radius: var(--radius-sm);
  background: #1f1f1f;
  color: var(--text-primary);
  padding: 0 var(--space-2);
}

.login-box input:focus {
  border-color: var(--focus);
  outline: none;
}

.login-button {
  width: 100%;
}

.login-message {
  min-height: 16px;
  margin: 0;
  color: var(--bar-low);
}

.app-shell {
  min-height: 100vh;
  padding: var(--space-4);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: 54px;
  margin-bottom: var(--space-3);
}

h1 {
  margin: 0;
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0;
}

.topbar p {
  margin: var(--space-1) 0 0;
  color: var(--text-dim);
}

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.file-input {
  display: none;
}

.countdown {
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  min-width: 92px;
  text-align: right;
}

.current-user {
  max-width: 190px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.button-primary,
.auth-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  border: 1px solid var(--control-border);
  border-radius: var(--radius-sm);
  background: var(--control-bg);
  color: #e8edf4;
  cursor: pointer;
  text-decoration: none;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.button-primary {
  min-width: 104px;
  padding: 0 var(--space-3);
}

.upload-button {
  min-width: 142px;
}

.logout-button {
  min-width: 70px;
}

.button-primary:hover,
.auth-button:hover {
  background: #4a5260;
  border-color: #687384;
}

.button-primary:focus-visible,
.auth-button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.button-primary:disabled {
  background: var(--control-disabled);
  border-color: #4a4d52;
  color: #aab0b8;
  cursor: default;
}

.button-icon {
  font-size: 16px;
  line-height: 1;
}

.grid-panel {
  position: relative;
  min-height: calc(100vh - 86px);
  border: 1px solid var(--line-soft);
  background: var(--grid-bg);
}

.grid-scroll {
  width: 100%;
  height: calc(100vh - 86px);
  overflow: auto;
}

.usage-grid {
  width: 100%;
  min-width: 840px;
  border-collapse: collapse;
  table-layout: fixed;
  background: var(--grid-bg);
}

.usage-grid th {
  height: 34px;
  padding: 0 var(--space-2);
  border-right: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  background: var(--header-bg);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  text-align: left;
}

.usage-grid td {
  height: var(--row-height);
  padding: 0 var(--space-2);
  border-right: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  color: var(--text-primary);
  vertical-align: middle;
}

.usage-grid tr:nth-child(odd) td {
  background: var(--grid-bg);
}

.usage-grid tr:nth-child(even) td {
  background: var(--grid-alt-bg);
}

.usage-grid tr:hover td {
  background: var(--grid-hover-bg);
}

.rank-col {
  width: 40px;
}

.updated-col {
  width: 98px;
}

.auth-col {
  width: 86px;
}

.account-cell {
  overflow: hidden;
  color: var(--text-primary);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-cell,
.updated-cell {
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.limit-cell {
  display: grid;
  align-content: center;
  min-height: var(--row-height);
  gap: var(--space-2);
}

.limit-percent {
  color: var(--text-muted);
  font-size: 16px;
  font-weight: 400;
  line-height: 1;
}

.limit-bar {
  width: 100%;
  height: 12px;
  border: 1px solid #52565d;
  background: var(--bar-bg);
}

.limit-fill {
  display: block;
  width: var(--percent, 0%);
  height: 100%;
  background: var(--bar-low);
}

.limit-fill.is-good {
  background: var(--bar-good);
}

.limit-fill.is-warn {
  background: var(--bar-warn);
}

.reset-text {
  min-height: 14px;
  color: var(--text-dim);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-button {
  width: 62px;
  height: 32px;
}

.empty-cell {
  height: 180px;
  color: var(--text-dim);
  text-align: center;
}

.update-mask {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(35, 35, 35, 0.42);
  pointer-events: none;
}

.update-mask.is-visible {
  display: flex;
}

.update-mask span {
  min-width: 168px;
  border: 1px solid #4c535e;
  border-radius: var(--radius-md);
  background: #2e333b;
  color: var(--text-muted);
  padding: var(--space-3) var(--space-4);
  text-align: center;
}

@media (max-width: 760px) {
  .app-shell {
    padding: var(--space-2);
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar {
    justify-content: space-between;
  }

  .grid-panel,
  .grid-scroll {
    min-height: calc(100vh - 118px);
    height: calc(100vh - 118px);
  }
}
