:root {
  --bg: #f3f5f8;
  --bg-elevated: #ffffff;
  --bg-soft: #eef2f7;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success-bg: #ecfdf3;
  --success-text: #166534;
  --error-bg: #fef2f2;
  --error-text: #991b1b;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 20px rgba(15, 23, 42, 0.04);
  --radius: 16px;
  --sidebar-width: 248px;
  --font: "Segoe UI", "IBM Plex Sans", "Helvetica Neue", sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

button, input {
  font: inherit;
}

.muted {
  color: var(--text-muted);
}

/* Auth */
.layout-auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(900px 420px at 15% 0%, #dbeafe 0%, transparent 55%),
    radial-gradient(700px 360px at 100% 10%, #e2e8f0 0%, transparent 50%),
    var(--bg);
}

.auth-card {
  width: min(420px, 100%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 2rem;
}

.auth-brand {
  text-align: center;
  margin-bottom: 1.75rem;
}

.auth-brand h1 {
  margin: 0.85rem 0 0.35rem;
  font-size: 1.55rem;
  letter-spacing: -0.03em;
}

.auth-brand p {
  margin: 0;
  color: var(--text-muted);
}

.logo-mark {
  display: inline-block;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: linear-gradient(145deg, #2563eb 0%, #60a5fa 100%);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.28);
  flex-shrink: 0;
}

.auth-form {
  display: grid;
  gap: 1rem;
}

.field {
  display: grid;
  gap: 0.4rem;
}

.field span {
  font-size: 0.875rem;
  font-weight: 600;
}

.field input {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  padding: 0.75rem 0.9rem;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 0.68rem 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s, box-shadow 0.15s;
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled,
.btn.disabled {
  opacity: 0.5;
  pointer-events: none;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 0.42rem 0.72rem;
  font-size: 0.875rem;
  border-radius: 9px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.2);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-secondary:hover {
  background: var(--bg-soft);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--bg-soft);
  color: var(--text);
}

.btn-danger {
  background: #fff;
  color: var(--danger);
  border-color: #fecaca;
}

.btn-danger:hover {
  background: var(--error-bg);
  border-color: #fca5a5;
}

/* Alerts */
.alert {
  border-radius: 12px;
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.alert-error {
  background: var(--error-bg);
  color: var(--error-text);
  border: 1px solid #fecaca;
}

.alert-success {
  background: var(--success-bg);
  color: var(--success-text);
  border: 1px solid #bbf7d0;
}

.success-preview {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 1rem;
  margin-top: 0.85rem;
  align-items: start;
}

.success-preview img {
  width: 96px;
  height: 96px;
  object-fit: contain;
  background: #fff;
  border-radius: 10px;
  border: 1px solid #bbf7d0;
  padding: 4px;
}

.url-line code {
  font-size: 0.8rem;
  word-break: break-all;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.65rem;
}

/* App layout */
.layout-app {
  min-height: 100vh;
  background: var(--bg);
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  background: #0f172a;
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  padding: 1.15rem 0.9rem;
  z-index: 40;
  transform: translateX(0);
  transition: transform 0.2s ease;
  border-right: 1px solid rgba(148, 163, 184, 0.08);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.7rem 1.35rem;
}

.brand-text {
  display: grid;
  gap: 0.05rem;
  min-width: 0;
}

.brand-text strong {
  font-size: 0.98rem;
  letter-spacing: -0.02em;
  color: #fff;
}

.brand-text span {
  font-size: 0.72rem;
  color: #94a3b8;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sidebar-nav {
  display: grid;
  gap: 0.3rem;
  flex: 1;
  align-content: start;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.72rem 0.8rem;
  border-radius: 11px;
  color: #94a3b8;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  cursor: pointer;
  font-weight: 560;
  font-size: 0.94rem;
  transition: background 0.15s, color 0.15s;
}

.nav-link:hover {
  background: rgba(148, 163, 184, 0.1);
  color: #f8fafc;
}

.nav-link.active {
  background: rgba(37, 99, 235, 0.22);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(96, 165, 250, 0.18);
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding-top: 0.85rem;
  border-top: 1px solid rgba(148, 163, 184, 0.12);
}

.logout-btn {
  color: #fca5a5;
}

.logout-btn:hover {
  background: rgba(248, 113, 113, 0.12);
  color: #fecaca;
}

.main-wrap {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.95rem 1.6rem;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-title-wrap {
  flex: 1;
  min-width: 0;
}

.page-title {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: -0.03em;
  font-weight: 700;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.38rem 0.78rem;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.84rem;
  font-weight: 600;
}

.user-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
}

.menu-toggle {
  display: none;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: #fff;
  padding: 10px 9px;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
}

.menu-toggle span {
  display: block;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}

.sidebar-backdrop {
  display: none;
}

.content {
  padding: 1.5rem 1.6rem 2rem;
  width: min(1120px, 100%);
  margin: 0 auto;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.15rem;
}

.stat-card,
.panel,
.image-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat-card {
  padding: 1.1rem 1.15rem;
  display: flex;
  align-items: center;
  gap: 0.95rem;
  min-width: 0;
}

.stat-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  flex-shrink: 0;
  background: var(--primary-soft);
  position: relative;
}

.stat-icon::before,
.stat-icon::after {
  content: "";
  position: absolute;
  background: var(--primary);
}

.stat-icon-images::before {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  top: 11px;
  left: 11px;
  opacity: 0.9;
}

.stat-icon-images::after {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  top: 17px;
  left: 17px;
  opacity: 0.45;
}

.stat-icon-storage::before {
  width: 16px;
  height: 12px;
  border-radius: 3px;
  top: 15px;
  left: 13px;
}

.stat-icon-storage::after {
  width: 8px;
  height: 2px;
  top: 19px;
  left: 17px;
  background: #fff;
}

.stat-icon-user {
  background: #f1f5f9;
}

.stat-icon-user::before {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  top: 11px;
  left: 16px;
  background: #64748b;
}

.stat-icon-user::after {
  width: 16px;
  height: 9px;
  border-radius: 8px 8px 3px 3px;
  top: 22px;
  left: 13px;
  background: #64748b;
}

.stat-label {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.stat-value {
  margin: 0.15rem 0 0;
  font-size: 1.55rem;
  font-weight: 750;
  letter-spacing: -0.04em;
  line-height: 1.15;
}

.stat-value-sm {
  font-size: 1.2rem;
  text-transform: none;
}

.panel {
  padding: 1.2rem 1.25rem 1.25rem;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.panel-header h2 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.panel-header p {
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
}

.panel-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.empty-state {
  text-align: center;
  padding: 2.4rem 1rem;
  color: var(--text-muted);
}

.empty-state .btn {
  margin-top: 0.85rem;
}

.recent-list {
  display: grid;
  gap: 0.65rem;
}

.recent-item {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 1rem;
  align-items: center;
  padding: 0.7rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #fff;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.recent-item:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
}

.recent-thumb {
  width: 112px;
  height: 72px;
  border-radius: 10px;
  background:
    linear-gradient(45deg, #f1f5f9 25%, transparent 25%),
    linear-gradient(-45deg, #f1f5f9 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f1f5f9 75%),
    linear-gradient(-45deg, transparent 75%, #f1f5f9 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-color: #e2e8f0;
  overflow: hidden;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
}

.recent-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.recent-meta {
  display: grid;
  gap: 0.28rem;
  min-width: 0;
}

.recent-meta strong,
.image-body h3 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.92rem;
}

.recent-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.recent-tags span {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.recent-date {
  font-size: 0.8rem;
}

/* Upload */
.drop-zone {
  border: 1.5px dashed #cbd5e1;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fbfdff 0%, #f8fafc 100%);
  min-height: 240px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  outline: none;
  overflow: hidden;
}

.drop-zone.has-file {
  cursor: default;
  border-style: solid;
  border-color: #cbd5e1;
  background: #fff;
  place-items: stretch;
}

.drop-zone:hover,
.drop-zone:focus,
.drop-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.12);
}

.drop-zone.has-file:hover,
.drop-zone.has-file:focus {
  background: #fff;
  border-color: #cbd5e1;
  box-shadow: none;
}

.drop-zone-content {
  text-align: center;
  padding: 2rem;
}

.drop-zone.has-file .drop-zone-content {
  display: none;
}

.drop-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 1rem;
  border-radius: 16px;
  background: linear-gradient(145deg, rgba(37, 99, 235, 0.12), rgba(37, 99, 235, 0.28));
  position: relative;
}

.drop-icon::before {
  content: "";
  position: absolute;
  inset: 18px 22px 14px;
  border: 2px solid var(--primary);
  border-radius: 4px;
}

.drop-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 12px;
  width: 2px;
  height: 18px;
  background: var(--primary);
  transform: translateX(-50%);
  box-shadow: -5px 8px 0 -1px var(--primary), 5px 8px 0 -1px var(--primary);
}

.preview-wrap {
  display: none;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 1.25rem;
  align-items: center;
  width: 100%;
  padding: 1.25rem;
}

.drop-zone.has-file .preview-wrap {
  display: grid;
}

.preview-thumb {
  width: 180px;
  height: 140px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background:
    linear-gradient(45deg, #f1f5f9 25%, transparent 25%),
    linear-gradient(-45deg, #f1f5f9 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f1f5f9 75%),
    linear-gradient(-45deg, transparent 75%, #f1f5f9 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-color: #e2e8f0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.preview-wrap img,
.preview-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.preview-info {
  min-width: 0;
  display: grid;
  gap: 0.35rem;
}

.preview-info p {
  margin: 0;
}

.preview-info #preview-name {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.form-actions {
  margin-top: 1rem;
  display: flex;
  justify-content: flex-end;
}

/* Library */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.image-card {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s, box-shadow 0.15s;
}

.image-card:hover {
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
}

.image-thumb {
  aspect-ratio: 16 / 11;
  background:
    linear-gradient(45deg, #f1f5f9 25%, transparent 25%),
    linear-gradient(-45deg, #f1f5f9 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f1f5f9 75%),
    linear-gradient(-45deg, transparent 75%, #f1f5f9 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
  background-color: #e2e8f0;
  overflow: hidden;
  display: grid;
  place-items: center;
}

.image-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.image-body {
  padding: 1rem;
  display: grid;
  gap: 0.75rem;
}

.image-body h3 {
  margin: 0;
  font-size: 0.9rem;
}

.image-meta {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}

.image-meta li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.84rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px dashed var(--border);
}

.image-meta li:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.image-meta span {
  color: var(--text-muted);
}

.url-box input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0.5rem 0.65rem;
  background: #f8fafc;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.card-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.delete-form {
  margin: 0;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.page-info {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.error-card {
  text-align: center;
}

.error-code {
  margin: 0;
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--primary);
}

.error-card h1 {
  margin: 0.25rem 0 0.5rem;
}

.auth-footer {
  margin: 1.15rem 0 0;
  text-align: center;
  font-size: 0.9rem;
}

.auth-footer a {
  color: var(--primary);
  font-weight: 600;
}

.auth-footer a:hover {
  text-decoration: underline;
}

.content-settings {
  display: grid;
  gap: 1.15rem;
}

.settings-form {
  display: grid;
  gap: 0.9rem;
  max-width: 520px;
}

.form-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 0.85rem;
}

.ip-current {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 0.85rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f8fafc;
  margin-bottom: 1rem;
}

.ip-current code {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}

.inline-add-ip {
  margin: 0;
}

.toggle-form {
  margin-bottom: 1rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.status-on {
  background: #ecfdf3;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.status-off {
  background: #f8fafc;
  color: #64748b;
  border: 1px solid var(--border);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  padding: 0.75rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: #f8fafc;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table code {
  font-size: 0.86rem;
}

.table-actions {
  width: 1%;
  white-space: nowrap;
}

.table-actions form {
  margin: 0;
}

.empty-state.compact {
  padding: 1.25rem 0.5rem;
}

body.sidebar-open {
  overflow: hidden;
}

@media (max-width: 960px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .sidebar {
    transform: translateX(-105%);
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 30;
  }

  .main-wrap {
    margin-left: 0;
  }

  .menu-toggle {
    display: inline-flex;
  }

  .content {
    padding: 1.15rem 1rem 1.75rem;
  }

  .topbar {
    padding: 0.85rem 1rem;
  }

  .preview-wrap,
  .success-preview {
    grid-template-columns: 1fr;
  }

  .preview-thumb {
    width: 100%;
    height: 180px;
  }

  .preview-wrap img,
  .success-preview img {
    width: 100%;
    height: 200px;
  }

  .panel-header {
    flex-direction: column;
    align-items: stretch;
  }

  .panel-actions .btn {
    width: 100%;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .recent-item {
    grid-template-columns: 88px minmax(0, 1fr);
    gap: 0.75rem;
  }

  .recent-thumb {
    width: 88px;
    height: 64px;
  }
}
