:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e4e6eb;
  --text: #1c1f26;
  --text-muted: #6b7280;
  --accent: #4f46e5;
  --accent-dark: #4338ca;
  --accent-soft: #eef2ff;
  --green: #16a34a;
  --green-soft: #ecfdf3;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --sidebar-bg: #14161f;
  --sidebar-text: #b8bcc8;
  --sidebar-text-active: #ffffff;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 22px;
}

.brand-logo-wrap {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.brand-logo-wrap img {
  width: 84%;
  height: 84%;
  object-fit: contain;
}

.brand-logo-wrap.big {
  width: 52px;
  height: 52px;
  margin: 0 auto 12px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.brand-text strong {
  color: #fff;
  font-size: 15px;
}

.brand-text span {
  font-size: 11px;
  color: var(--sidebar-text);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  font-weight: 500;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  text-decoration: none;
}

.nav-link.is-active {
  background: var(--accent);
  color: #fff;
}

.nav-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.9;
}

.nav-icon svg {
  width: 18px;
  height: 18px;
}

.sidebar-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 14px;
  margin-top: 14px;
}

.me {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 10px;
}

.me-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  text-transform: uppercase;
  flex-shrink: 0;
}

.me-info {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  overflow: hidden;
}

.me-info strong {
  color: #fff;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.me-info span {
  font-size: 11px;
  color: var(--sidebar-text);
}

.logout-row {
  text-align: center;
  margin-top: 4px;
}

.btn-dark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 140px;
  padding: 8px 22px;
  background: #262a35;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 4px;
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}

.btn-dark:hover {
  background: #30343f;
  color: #fff;
  text-decoration: none;
}

/* Content */
.content {
  flex: 1;
  padding: 28px 36px 60px;
  min-width: 0;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 22px;
  margin: 0;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.search-form {
  display: flex;
}

.search-input {
  min-width: 240px;
}

/* Period tabs */
.period-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.period-tab {
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
}

.period-tab:hover {
  text-decoration: none;
  color: var(--text);
}

.period-tab.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-card-accent {
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  border: none;
}

.stat-card-accent .stat-label,
.stat-card-accent .stat-sub {
  color: rgba(255, 255, 255, 0.8);
}

.stat-card-accent .stat-value {
  color: #fff;
}

.stat-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
}

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* Panels & tables */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  overflow: hidden;
  margin-bottom: 24px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 0;
}

.panel-header h2 {
  font-size: 15px;
  margin: 0 0 14px;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th, .table td {
  text-align: left;
  padding: 11px 20px;
  border-bottom: 1px solid var(--border);
  box-shadow: inset -1px 0 0 0 var(--border);
  font-size: 13.5px;
}

.table th:last-child, .table td:last-child {
  box-shadow: none;
}

.table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr[onclick] {
  cursor: pointer;
}

.table tbody tr[onclick]:hover {
  background: var(--accent-soft);
}

.muted {
  color: var(--text-muted);
  padding: 20px;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-active {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.badge-completed {
  background: var(--green-soft);
  color: var(--green);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: 6px;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover {
  background: var(--accent-dark);
  text-decoration: none;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12.5px;
}

.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
}

.btn-outline:hover {
  background: var(--accent-soft);
}

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

.btn-danger:hover {
  background: #fde2e2;
}

.link {
  font-weight: 600;
  font-size: 13px;
}

.link.small {
  font-size: 12.5px;
  align-self: center;
}

/* Forms */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  max-width: 640px;
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-row {
  display: flex;
  align-items: flex-end;
  gap: 14px;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-items: start;
}

.form-row-2 label {
  width: 100%;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

label.checkbox {
  flex-direction: row;
  align-items: center;
  font-weight: 500;
}

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  font-weight: 400;
}

input[readonly] {
  background: var(--bg);
  color: var(--text-muted);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea {
  resize: vertical;
}

/* Client combobox */
.combo {
  position: relative;
}

.combo-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
  max-height: 240px;
  overflow-y: auto;
  z-index: 20;
}

.combo-option {
  padding: 9px 12px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border);
}

.combo-option:last-child {
  border-bottom: none;
}

.combo-option:hover {
  background: var(--accent-soft);
}

.combo-option span {
  color: var(--text-muted);
  font-size: 12.5px;
  white-space: nowrap;
}

.combo-empty {
  padding: 10px 12px;
  color: var(--text-muted);
  font-size: 13px;
}

/* Order photos */
.panel-body {
  padding: 4px 20px 20px;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.photo-empty {
  padding: 0;
  grid-column: 1 / -1;
}

.photo-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.photo-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-item form {
  position: absolute;
  top: 4px;
  right: 4px;
}

.photo-delete {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.photo-delete:hover {
  background: rgba(220, 38, 38, 0.9);
}

.photo-upload-form {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

/* Flash */
.flash {
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  margin-bottom: 18px;
  font-weight: 500;
}

.flash-ok {
  background: var(--green-soft);
  color: var(--green);
}

.flash-error {
  background: var(--red-soft);
  color: var(--red);
}

/* Auth */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--sidebar-bg);
  padding: 20px;
}

.auth-card {
  background: none;
  padding: 20px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}

.auth-card label {
  text-align: left;
  color: #fff;
}

.auth-card input {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 0;
  color: #fff;
}

.auth-card input::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

.auth-card input:focus {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.35);
}

.auth-card input:-webkit-autofill {
  -webkit-text-fill-color: #fff;
  -webkit-box-shadow: 0 0 0 1000px rgba(255, 255, 255, 0.1) inset;
  transition: background-color 9999s ease-in-out 0s;
}

.auth-card .btn-dark {
  align-self: center;
  margin-top: 10px;
}

@media (max-width: 760px) {
  .app {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
  }
  .nav {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .sidebar-footer {
    margin-left: auto;
    border-top: none;
    padding-top: 0;
    display: flex;
    align-items: center;
  }
  .content {
    padding: 20px;
  }
  .form-row-2 {
    grid-template-columns: 1fr;
  }
  .search-input {
    min-width: 0;
    width: 100%;
  }
  .header-actions {
    width: 100%;
  }
  .search-form {
    flex: 1 1 100%;
  }
}
