/* ===== Organic/Natural Design System ===== */

:root {
  --bg: #FDFCF8;
  --fg: #2C2C24;
  --primary: #5D7052;
  --primary-fg: #F3F4F1;
  --secondary: #C18C5D;
  --accent: #E6DCCD;
  --muted: #F0EBE5;
  --muted-fg: #78786C;
  --border: #DED8CF;
  --destructive: #A85448;
  --card: #FEFEFA;
  --shadow-moss: 0 4px 20px -2px rgba(93,112,82,.15);
  --shadow-float: 0 10px 40px -10px rgba(193,140,93,.2);
  --radius: 1.5rem;
}

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

body {
  font-family: 'Nunito', 'Quicksand', system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

h1,h2,h3,h4 { font-family: 'Fraunces', Georgia, serif; }

.grain-overlay {
  position: fixed; inset: 0; z-index: 9999; pointer-events: none;
  opacity: .035; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 200px;
}

/* ===== Navbar ===== */
.navbar {
  position: sticky; top: .75rem; z-index: 100;
  margin: .75rem 1rem 0;
  background: rgba(255,255,255,.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(222,216,207,.5);
  border-radius: 9999px;
  padding: 0 1.25rem;
  height: 52px;
  box-shadow: var(--shadow-moss);
  transition: all .3s;
}
.navbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; max-width: 1200px; margin: 0 auto; height: 100%;
}
.navbar-brand {
  display: flex; align-items: center; gap: .5rem;
  font-family: 'Fraunces', serif; font-weight: 700; font-size: 1.05rem;
  color: var(--fg);
}
.brand-icon {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary); display: flex; align-items: center; justify-content: center;
}
.navbar-actions { display: flex; align-items: center; gap: .75rem; }
.navbar-user { font-size: .85rem; color: var(--muted-fg); display: flex; align-items: center; gap: .3rem; }
.mobile-menu-btn {
  display: none; background: none; border: none; cursor: pointer;
  color: var(--fg); padding: 4px;
}

/* ===== Container ===== */
.container { max-width: 1200px; margin: 1.5rem auto; padding: 0 1rem; flex: 1; width: 100%; }

/* ===== Stats ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
  box-shadow: var(--shadow-moss);
  transition: all .3s;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: ''; position: absolute; top: -30px; right: -30px;
  width: 80px; height: 80px; border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
  opacity: .08; transition: transform .3s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-float); }
.stat-card:hover::before { transform: scale(1.2); }
.stat-icon { margin-bottom: .5rem; color: var(--muted-fg); }
.stat-number { font-family: 'Fraunces', serif; font-size: 2rem; font-weight: 700; color: var(--fg); }
.stat-label { font-size: .8rem; color: var(--muted-fg); margin-top: .15rem; font-weight: 500; }
.stat-active .stat-number { color: var(--primary); }
.stat-active .stat-icon { color: var(--primary); }
.stat-active::before { background: var(--primary); }
.stat-expired .stat-number { color: var(--secondary); }
.stat-expired .stat-icon { color: var(--secondary); }
.stat-expired::before { background: var(--secondary); }
.stat-revoked .stat-number { color: var(--destructive); }
.stat-revoked .stat-icon { color: var(--destructive); }
.stat-revoked::before { background: var(--destructive); }

/* ===== Toolbar ===== */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: .75rem; margin-bottom: 1rem;
}
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: .5rem; }
.filter-form { display: flex; align-items: center; gap: .5rem; }
.filter-form select, .filter-form input[type=text] {
  padding: .55rem .9rem;
  border: 1px solid var(--border);
  border-radius: 9999px;
  font-size: .85rem;
  background: rgba(255,255,255,.5);
  font-family: inherit;
  color: var(--fg);
  transition: all .3s;
}
.filter-form select:focus, .filter-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(93,112,82,.15);
}
.filter-form input[type=text] { width: 180px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .55rem 1.25rem;
  border: none; border-radius: 9999px;
  font-size: .85rem; font-weight: 600; font-family: inherit;
  cursor: pointer; text-decoration: none;
  transition: all .3s; white-space: nowrap;
}
.btn:hover { transform: scale(1.03); }
.btn:active { transform: scale(.97); }
.btn-primary {
  background: var(--primary); color: var(--primary-fg);
  box-shadow: 0 4px 16px -2px rgba(93,112,82,.25);
}
.btn-primary:hover { box-shadow: 0 6px 24px -4px rgba(93,112,82,.35); }
.btn-outline {
  background: transparent; color: var(--secondary);
  border: 2px solid var(--secondary);
  padding: .45rem 1.1rem;
}
.btn-outline:hover { background: rgba(193,140,93,.08); }
.btn-ghost {
  background: transparent; color: var(--primary);
}
.btn-ghost:hover { background: rgba(93,112,82,.08); }
.btn-warn {
  background: var(--secondary); color: #fff;
  box-shadow: 0 2px 8px rgba(193,140,93,.2);
}
.btn-danger {
  background: var(--destructive); color: #fff;
  box-shadow: 0 2px 8px rgba(168,84,72,.2);
}
.btn-sm { padding: .3rem .75rem; font-size: .78rem; }
.btn-block { width: 100%; justify-content: center; }

/* ===== Layout ===== */

.table-wrapper {
  background: var(--card);
  border: 1px solid rgba(222,216,207,.5);
  border-radius: var(--radius);
  box-shadow: var(--shadow-moss);
  overflow-x: auto;
}
.table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.table thead { background: var(--muted); }
.table th {
  padding: .75rem 1rem; text-align: left;
  font-weight: 600; color: var(--muted-fg); font-size: .78rem;
  letter-spacing: .03em; text-transform: uppercase;
  border-bottom: 2px solid var(--border);
}
.table td {
  padding: .65rem 1rem;
  border-bottom: 1px solid rgba(222,216,207,.3);
  vertical-align: middle;
}
.table tbody tr { transition: background .2s; }
.table tbody tr:hover { background: rgba(93,112,82,.03); }
.empty-row { text-align: center; color: var(--muted-fg); padding: 3rem !important; }

.key-code {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: .88rem;
  background: var(--muted);
  padding: .25rem .5rem;
  border-radius: .5rem;
  cursor: pointer;
  user-select: all;
  word-break: break-all;
  transition: background .2s;
  border: 1px solid transparent;
}
.key-code:hover { background: var(--accent); border-color: var(--border); }

.duration-tag {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 9999px;
  font-size: .75rem;
  font-weight: 600;
  background: rgba(93,112,82,.08);
  color: var(--primary);
}
.label-cell { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted-fg); font-size: .8rem; }
.actions { white-space: nowrap; display: flex; gap: .25rem; }
.empty-state { display: flex; flex-direction: column; align-items: center; gap: .75rem; color: var(--muted-fg); padding: 2rem 0; }

/* ===== Badges ===== */
.badge {
  display: inline-block; padding: .2rem .6rem;
  border-radius: 9999px; font-size: .72rem; font-weight: 600;
}
.badge-active { background: rgba(93,112,82,.12); color: var(--primary); }
.badge-expired { background: rgba(193,140,93,.12); color: #96722E; }
.badge-revoked { background: rgba(168,84,72,.1); color: var(--destructive); }
.text-expired { color: var(--destructive); font-weight: 600; }
.text-muted { color: var(--muted-fg); }
.expires-time { font-family: 'SF Mono','Fira Code',monospace; font-size: .78rem; }

/* ===== Mobile Cards ===== */
.card-list { display: flex; flex-direction: column; gap: .75rem; }
.key-card {
  background: var(--card);
  border: 1px solid rgba(222,216,207,.5);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow-moss);
  transition: all .3s;
}
.key-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-float); }
.key-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .5rem; }
.key-card .key-code { display: block; margin-bottom: .5rem; padding: .5rem .7rem; font-size: .85rem; }
.key-card-meta {
  display: flex; gap: .75rem; font-size: .75rem; color: var(--muted-fg);
  margin-bottom: .5rem; flex-wrap: wrap;
}
.key-card-meta span { display: flex; align-items: center; gap: .25rem; }
.key-card-actions { display: flex; gap: .35rem; justify-content: flex-end; }

/* ===== Pagination ===== */
.pagination {
  display: flex; align-items: center; justify-content: center;
  gap: .75rem; margin-top: 1.25rem;
}
.page-info { font-size: .85rem; color: var(--muted-fg); }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(44,44,36,.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal {
  background: var(--card);
  border-radius: 2rem;
  width: 90%; max-width: 440px;
  box-shadow: var(--shadow-float);
  animation: modalIn .3s ease;
  border: 1px solid rgba(222,216,207,.5);
}
@keyframes modalIn { from { transform: translateY(16px) scale(.97); opacity: 0; } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.25rem 1.5rem .75rem;
}
.modal-header h3 { font-size: 1.15rem; }
.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--muted-fg); padding: 4px; border-radius: 50%;
  transition: all .2s;
}
.modal-close:hover { background: var(--muted); color: var(--fg); }
.modal-body { padding: .75rem 1.5rem 1rem; }
.modal-footer {
  padding: .75rem 1.5rem 1.25rem;
  display: flex; justify-content: flex-end; gap: .5rem;
}

/* ===== Duration Chips ===== */
.duration-options { display: flex; gap: .5rem; flex-wrap: wrap; }
.duration-chip {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .5rem 1rem; border-radius: 9999px;
  border: 2px solid var(--border);
  font-size: .85rem; font-weight: 600; cursor: pointer;
  transition: all .2s; color: var(--muted-fg);
  background: transparent;
}
.duration-chip input { display: none; }
.duration-chip.active, .duration-chip:has(input:checked) {
  border-color: var(--primary);
  background: rgba(93,112,82,.1);
  color: var(--primary);
}
.duration-chip:hover { border-color: var(--primary); }

/* ===== Forms ===== */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .4rem; color: var(--fg); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: .6rem 1rem;
  border: 1px solid var(--border);
  border-radius: 9999px;
  font-size: .85rem; font-family: inherit;
  background: rgba(255,255,255,.5);
  color: var(--fg);
  transition: all .3s;
}
.form-group input:focus, .form-group select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(93,112,82,.12);
}

/* ===== Auth ===== */
.auth-wrapper {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
}
.auth-wrapper::before {
  content: ''; position: absolute; top: 10%; left: -5%;
  width: 300px; height: 300px;
  background: var(--primary); opacity: .07;
  border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
  filter: blur(60px);
}
.auth-wrapper::after {
  content: ''; position: absolute; bottom: 10%; right: -5%;
  width: 250px; height: 250px;
  background: var(--secondary); opacity: .07;
  border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%;
  filter: blur(60px);
}
.auth-card {
  background: var(--card);
  border: 1px solid rgba(222,216,207,.5);
  border-radius: 2rem;
  padding: 2.5rem 2rem;
  width: 360px; max-width: 92vw;
  box-shadow: var(--shadow-float);
  text-align: center;
  position: relative; z-index: 1;
}
.auth-icon {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); margin: 0 auto 1rem;
  display: flex; align-items: center; justify-content: center;
}
.auth-card h2 { font-size: 1.3rem; margin-bottom: .25rem; }
.auth-subtitle { color: var(--muted-fg); font-size: .85rem; margin-bottom: 1.5rem; }

/* ===== Alert ===== */
.alert { padding: .6rem 1rem; border-radius: 1rem; font-size: .85rem; margin-bottom: 1rem; }
.alert-error { background: rgba(168,84,72,.1); color: var(--destructive); }
.alert-success { background: rgba(93,112,82,.1); color: var(--primary); }

/* ===== Toast ===== */
.toast {
  position: fixed; top: 5rem; right: 1rem;
  padding: .65rem 1.25rem; border-radius: 9999px;
  font-size: .85rem; font-weight: 600; z-index: 300;
  box-shadow: var(--shadow-float);
  animation: toastIn .3s ease;
}
@keyframes toastIn { from { transform: translateX(30px); opacity: 0; } }
.toast-success { background: var(--primary); color: var(--primary-fg); }
.toast-error { background: var(--destructive); color: #fff; }

/* ===== Footer ===== */
.footer {
  text-align: center; padding: 1.25rem;
  font-size: .8rem; color: var(--muted-fg);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .navbar { margin: .5rem .5rem 0; padding: 0 1rem; height: 48px; }
  .navbar-actions { display: none; }
  .navbar-actions.show {
    display: flex; flex-direction: column;
    position: absolute; top: 56px; right: 0; left: 0;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 1.5rem;
    padding: 1rem;
    box-shadow: var(--shadow-float);
    margin: 0 .5rem;
    gap: .5rem;
  }
  .mobile-menu-btn { display: block; }
  .container { padding: 0 .75rem; margin-top: 1rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: .65rem; }
  .stat-card { padding: 1rem; }
  .stat-number { font-size: 1.5rem; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-left, .toolbar-right { flex-wrap: wrap; }
  .filter-form { flex-wrap: wrap; width: 100%; }
  .filter-form input[type=text] { width: 100%; flex: 1; }
  .filter-form select { flex: 1; }

  .modal { border-radius: 1.5rem; max-width: 95vw; }
  .modal-header { padding: 1rem 1.25rem .5rem; }
  .modal-body { padding: .5rem 1.25rem .75rem; }
  .modal-footer { padding: .5rem 1.25rem 1rem; }
  .auth-card { padding: 2rem 1.5rem; width: 92vw; }
  .toast { right: .5rem; left: .5rem; text-align: center; }
  .duration-options { gap: .4rem; }
  .duration-chip { padding: .4rem .75rem; font-size: .8rem; }
}

@media (max-width: 380px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: .5rem; }
  .stat-card { padding: .75rem; }
  .stat-number { font-size: 1.3rem; }
  .stat-label { font-size: .7rem; }
  .key-card { padding: .75rem; }
  .key-card .key-code { font-size: .78rem; }
}
