/* =================================================================
   SRV Inventory — Mobile-first CSS
   ================================================================= */

/* -----------------------------------------------------------------
   1. CSS Custom Properties (Design tokens)
   ----------------------------------------------------------------- */
:root {
  /* Цвета */
  --c-bg:          #f4f5f7;
  --c-surface:     #ffffff;
  --c-surface-2:   #f0f1f3;
  --c-border:      #e2e4e9;
  --c-border-focus:#3b82f6;

  --c-text:        #1a1d23;
  --c-text-2:      #5a6070;
  --c-text-3:      #9aa0ad;

  --c-primary:     #3b82f6;
  --c-primary-d:   #2563eb;
  --c-primary-bg:  #eff6ff;

  --c-success:     #16a34a;
  --c-success-bg:  #f0fdf4;
  --c-warning:     #d97706;
  --c-warning-bg:  #fffbeb;
  --c-danger:      #dc2626;
  --c-danger-bg:   #fef2f2;
  --c-info:        #0891b2;
  --c-info-bg:     #ecfeff;

  /* Состояния деталей */
  --c-new:         #16a34a;
  --c-new-bg:      #f0fdf4;
  --c-used:        #d97706;
  --c-used-bg:     #fffbeb;
  --c-defective:   #dc2626;
  --c-defective-bg:#fef2f2;

  /* Совместимость */
  --c-certified:   #16a34a;
  --c-tested:      #2563eb;
  --c-unknown:     #9aa0ad;

  /* Размеры */
  --sidebar-w:     240px;
  --header-h:      56px;
  --radius:        8px;
  --radius-lg:     12px;
  --shadow:        0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg:     0 4px 16px rgba(0,0,0,.10);

  /* Шрифт */
  --font:          -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:     'SF Mono', 'Fira Code', monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --c-bg:        #0f1117;
    --c-surface:   #1a1d23;
    --c-surface-2: #22262f;
    --c-border:    #2e3340;
    --c-text:      #e8eaf0;
    --c-text-2:    #9aa0ad;
    --c-text-3:    #5a6070;
    --c-primary-bg:#1e3a5f;
    --c-success-bg:#052e16;
    --c-warning-bg:#431407;
    --c-danger-bg: #3f0e0e;
    --c-info-bg:   #0a2535;
    --c-new-bg:    #052e16;
    --c-used-bg:   #431407;
    --c-defective-bg: #3f0e0e;
  }
}

/* -----------------------------------------------------------------
   2. Reset & Base
   ----------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: var(--font);
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

button { font-family: inherit; cursor: pointer; }

input, select, textarea {
  font-family: inherit;
  font-size: 1rem;
}

/* -----------------------------------------------------------------
   3. App Layout
   ----------------------------------------------------------------- */
.app {
  display: flex;
  min-height: 100vh;
}

.app-loader {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--c-bg);
  z-index: 9999;
}

.app-loader__spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--c-border);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

.hidden { display: none !important; }

/* -----------------------------------------------------------------
   4. Sidebar
   ----------------------------------------------------------------- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transform: translateX(-100%);
  transition: transform .25s ease;
}

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

@media (min-width: 960px) {
  .sidebar { transform: translateX(0); position: sticky; height: 100vh; }
  .sidebar__toggle { display: none !important; }
  .main { margin-left: 0; }
}

.sidebar__logo {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 16px 16px;
  font-size: 1rem; font-weight: 600;
  border-bottom: 1px solid var(--c-border);
}

.sidebar__logo-icon { font-size: 1.4rem; }

.sidebar__nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.nav-group { margin-bottom: 4px; }

.nav-group__label {
  font-size: .7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--c-text-3);
  padding: 10px 16px 4px;
}

.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px;
  font-size: .875rem; color: var(--c-text-2);
  border-left: 3px solid transparent;
  transition: background .15s, color .15s;
  cursor: pointer;
  user-select: none;
}

.nav-link:hover { background: var(--c-surface-2); color: var(--c-text); }
.nav-link.active {
  background: var(--c-primary-bg);
  color: var(--c-primary);
  border-left-color: var(--c-primary);
  font-weight: 500;
}

.nav-link__icon { font-size: 1rem; width: 20px; text-align: center; }

.sidebar__user {
  padding: 12px 16px;
  border-top: 1px solid var(--c-border);
  font-size: .8rem; color: var(--c-text-2);
}

.sidebar__user-name { font-weight: 500; color: var(--c-text); }
.sidebar__user-role { margin-bottom: 8px; }

.sidebar__toggle {
  position: fixed; top: 12px; left: 12px;
  z-index: 200;
  width: 40px; height: 40px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 5px;
  padding: 8px;
  box-shadow: var(--shadow);
}

.sidebar__toggle span {
  display: block; width: 18px; height: 2px;
  background: var(--c-text);
  border-radius: 2px;
  transition: .2s;
}

/* -----------------------------------------------------------------
   5. Main content
   ----------------------------------------------------------------- */
.main {
  flex: 1;
  min-width: 0;
  padding: 16px;
  padding-top: 64px; /* под toggle на мобиле */
}

@media (min-width: 960px) {
  .main { padding: 24px 32px; }
}

/* -----------------------------------------------------------------
   6. Page header
   ----------------------------------------------------------------- */
.page-header {
  display: flex; align-items: flex-start;
  justify-content: space-between; flex-wrap: wrap; gap: 12px;
  margin-bottom: 20px;
}

.page-title {
  font-size: 1.25rem; font-weight: 600;
  color: var(--c-text);
}

.page-subtitle {
  font-size: .875rem; color: var(--c-text-2);
  margin-top: 2px;
}

/* -----------------------------------------------------------------
   7. Cards & Surfaces
   ----------------------------------------------------------------- */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.card__header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--c-border);
  font-weight: 500; font-size: .9rem;
}

.card__body { padding: 16px; }

/* -----------------------------------------------------------------
   8. Таблица
   ----------------------------------------------------------------- */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  box-shadow: var(--shadow);
}

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

thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: .75rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--c-text-2);
  background: var(--c-surface-2);
  border-bottom: 1px solid var(--c-border);
  white-space: nowrap;
}

tbody tr { border-bottom: 1px solid var(--c-border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--c-surface-2); }

tbody td { padding: 10px 14px; vertical-align: middle; }

/* -----------------------------------------------------------------
   9. Badges & Pills
   ----------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: .72rem; font-weight: 600;
  white-space: nowrap;
}

.badge--new       { background: var(--c-new-bg);       color: var(--c-new); }
.badge--used      { background: var(--c-used-bg);      color: var(--c-warning); }
.badge--defective { background: var(--c-defective-bg); color: var(--c-danger); }

.badge--certified { background: var(--c-success-bg); color: var(--c-success); }
.badge--tested    { background: var(--c-primary-bg);  color: var(--c-primary); }
.badge--unknown   { background: var(--c-surface-2);   color: var(--c-text-3); }
.badge--universal { background: var(--c-info-bg);     color: var(--c-info); }

.badge--draft            { background: var(--c-surface-2);  color: var(--c-text-2); }
.badge--pending_approval { background: var(--c-warning-bg); color: var(--c-warning); }
.badge--approved         { background: var(--c-success-bg); color: var(--c-success); }
.badge--rejected         { background: var(--c-danger-bg);  color: var(--c-danger); }

/* -----------------------------------------------------------------
   10. Buttons
   ----------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  font-size: .875rem; font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}

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

.btn--primary {
  background: var(--c-primary); color: #fff;
  border-color: var(--c-primary);
}
.btn--primary:hover:not(:disabled) { background: var(--c-primary-d); }

.btn--secondary {
  background: var(--c-surface); color: var(--c-text);
  border-color: var(--c-border);
}
.btn--secondary:hover:not(:disabled) { background: var(--c-surface-2); }

.btn--danger {
  background: var(--c-danger-bg); color: var(--c-danger);
  border-color: var(--c-danger);
}
.btn--danger:hover:not(:disabled) { background: var(--c-danger); color: #fff; }

.btn--sm { padding: 5px 10px; font-size: .8rem; }
.btn--icon { padding: 7px; }

/* -----------------------------------------------------------------
   11. Forms
   ----------------------------------------------------------------- */
.form-group { margin-bottom: 14px; }

.form-label {
  display: block; margin-bottom: 5px;
  font-size: .8rem; font-weight: 500; color: var(--c-text-2);
}

.form-label .required { color: var(--c-danger); margin-left: 2px; }

.form-control {
  width: 100%; padding: 8px 11px;
  font-size: .9rem;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  color: var(--c-text);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}

.form-control:focus {
  border-color: var(--c-border-focus);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

.form-control.error { border-color: var(--c-danger); }

.form-error {
  font-size: .78rem; color: var(--c-danger);
  margin-top: 4px;
}

.form-hint {
  font-size: .78rem; color: var(--c-text-3);
  margin-top: 4px;
}

select.form-control { 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='%239aa0ad' d='M6 8L0 0h12z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }

/* -----------------------------------------------------------------
   12. Filters bar
   ----------------------------------------------------------------- */
.filters {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-bottom: 16px;
}

.filters__search {
  flex: 1; min-width: 200px;
  position: relative;
}

.filters__search-icon {
  position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%);
  color: var(--c-text-3); font-size: .9rem;
  pointer-events: none;
}

.filters__search input {
  padding-left: 32px;
}

/* -----------------------------------------------------------------
   13. Pagination
   ----------------------------------------------------------------- */
.pagination {
  display: flex; align-items: center; justify-content: center;
  gap: 4px; padding: 16px 0;
}

.pagination__btn {
  min-width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  font-size: .875rem;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  color: var(--c-text-2);
  cursor: pointer;
  transition: .15s;
}

.pagination__btn:hover { background: var(--c-surface-2); color: var(--c-text); }
.pagination__btn.active {
  background: var(--c-primary); color: #fff;
  border-color: var(--c-primary);
}
.pagination__btn:disabled { opacity: .4; cursor: not-allowed; }

.pagination__info { font-size: .8rem; color: var(--c-text-2); padding: 0 8px; }

/* -----------------------------------------------------------------
   14. Modal
   ----------------------------------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 500;
  padding: 0;
}

@media (min-width: 640px) {
  .modal-overlay { align-items: center; padding: 16px; }
}

.modal {
  background: var(--c-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%; max-width: 600px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slide-up .2s ease;
}

@media (min-width: 640px) {
  .modal { border-radius: var(--radius-lg); animation: fade-in .15s ease; }
}

@keyframes slide-up {
  from { transform: translateY(40px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

@keyframes fade-in {
  from { opacity: 0; transform: scale(.97); }
  to   { opacity: 1; transform: scale(1); }
}

.modal__header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--c-border);
}

.modal__title { font-size: 1rem; font-weight: 600; }

.modal__close {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius); border: none;
  background: var(--c-surface-2); color: var(--c-text-2);
  font-size: 1.1rem; cursor: pointer;
}

.modal__body {
  flex: 1; overflow-y: auto;
  padding: 20px;
}

.modal__footer {
  padding: 14px 20px;
  border-top: 1px solid var(--c-border);
  display: flex; gap: 8px; justify-content: flex-end;
}

/* -----------------------------------------------------------------
   15. Empty state & Loaders
   ----------------------------------------------------------------- */
.empty-state {
  text-align: center; padding: 48px 16px;
  color: var(--c-text-2);
}

.empty-state__icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state__title { font-weight: 500; font-size: 1rem; margin-bottom: 6px; }
.empty-state__text { font-size: .875rem; color: var(--c-text-3); }

.loading-row td {
  text-align: center; padding: 32px;
  color: var(--c-text-3); font-size: .875rem;
}

/* -----------------------------------------------------------------
   16. Alert / Toast
   ----------------------------------------------------------------- */
.toast-container {
  position: fixed; bottom: 16px; right: 16px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 1000;
  max-width: calc(100vw - 32px);
}

.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: .875rem;
  animation: toast-in .2s ease;
  max-width: 360px;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

.toast--success { border-left: 3px solid var(--c-success); }
.toast--error   { border-left: 3px solid var(--c-danger); }
.toast--warning { border-left: 3px solid var(--c-warning); }

/* -----------------------------------------------------------------
   17. Login page
   ----------------------------------------------------------------- */
.page-login {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--c-bg); padding: 16px;
}

.login-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 380px;
  padding: 32px 28px;
}

.login-card__logo {
  text-align: center; margin-bottom: 24px;
  font-size: 1.5rem; font-weight: 700;
  color: var(--c-text);
}

.login-card__logo-sub {
  font-size: .8rem; font-weight: 400;
  color: var(--c-text-3); margin-top: 4px;
}

/* -----------------------------------------------------------------
   18. Item detail / composition
   ----------------------------------------------------------------- */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.detail-field__label {
  font-size: .72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--c-text-3); margin-bottom: 3px;
}

.detail-field__value { font-size: .9rem; color: var(--c-text); }

.composition-list { list-style: none; }

.composition-list__item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--c-border);
  font-size: .875rem;
}

.composition-list__item:last-child { border-bottom: none; }

/* -----------------------------------------------------------------
   19. Compatibility warning
   ----------------------------------------------------------------- */
.compat-banner {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: .875rem; margin-bottom: 12px;
}

.compat-banner--certified { background: var(--c-success-bg); color: var(--c-success); }
.compat-banner--tested    { background: var(--c-primary-bg);  color: var(--c-primary); }
.compat-banner--unknown   { background: var(--c-warning-bg);  color: var(--c-warning); }

/* -----------------------------------------------------------------
   20. Utility
   ----------------------------------------------------------------- */
.text-muted    { color: var(--c-text-2); }
.text-sm       { font-size: .8rem; }
.text-mono     { font-family: var(--font-mono); font-size: .85em; }
.text-right    { text-align: right; }
.fw-500        { font-weight: 500; }
.mt-4          { margin-top: 4px; }
.mt-8          { margin-top: 8px; }
.mt-16         { margin-top: 16px; }
.mb-16         { margin-bottom: 16px; }
.flex          { display: flex; }
.flex-center   { display: flex; align-items: center; }
.gap-8         { gap: 8px; }
.gap-12        { gap: 12px; }
.w-full        { width: 100%; }
.truncate      { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
