:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e3e5e9;
  --text: #1f2430;
  --text-muted: #6b7280;
  --primary: #2f6fed;
  --primary-dark: #2456bd;
  --danger: #e0453f;
  --success: #1a9c5e;
  --radius: 10px;
  --sidebar-w: 220px;
}

* { box-sizing: border-box; }

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

.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-wrap {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #eef2ff, #f5f6f8);
}
.login-card {
  background: var(--surface);
  padding: 36px 32px;
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(20, 30, 60, 0.08);
  width: 340px;
}
.login-card h1 { font-size: 19px; margin: 0 0 4px; }
.login-card .muted { color: var(--text-muted); margin: 0 0 20px; font-size: 13px; }
.login-card label { display: block; font-size: 13px; margin: 12px 0 4px; font-weight: 600; }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
.error-text { color: var(--danger); font-size: 13px; min-height: 18px; margin: 10px 0 0; }

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

.sidebar {
  width: var(--sidebar-w);
  background: #171b26;
  color: #cbd2e1;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  flex-shrink: 0;
}
.brand { color: #fff; font-weight: 700; font-size: 16px; padding: 0 8px 20px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-link {
  background: none; border: none; text-align: left; color: #cbd2e1;
  padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.nav-link:hover { background: #232a3a; color: #fff; }
.nav-link.active { background: var(--primary); color: #fff; }
.sidebar-footer { border-top: 1px solid #2a3040; padding-top: 12px; margin-top: 12px; }

.lang-switch { display: flex; gap: 4px; margin-bottom: 12px; }
.lang-switch button {
  background: none; border: 1px solid #3a4256; color: #9aa4bb; cursor: pointer;
  padding: 4px 9px; border-radius: 6px; font-size: 12px; font-weight: 700;
}
.lang-switch button:hover { color: #fff; border-color: #4a5570; }
.lang-switch button.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.lang-switch-login {
  position: absolute; top: 18px; right: 18px; justify-content: flex-end;
}
.lang-switch-login button {
  background: #fff; border: 1px solid var(--border); color: var(--text-muted);
}
.lang-switch-login button.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.current-user { color: #fff; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.btn-link {
  background: none; border: none; color: #9aa4bb; cursor: pointer; font-size: 13px;
  padding: 4px 0; display: block; text-align: left;
}
.btn-link:hover { color: #fff; }

.content { flex: 1; padding: 28px 34px; max-width: 1200px; }

.view-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap;
}
.view-header h2 { margin: 0; font-size: 20px; }
.header-actions { display: flex; gap: 8px; }

/* ---------- Buttons ---------- */
.btn {
  padding: 9px 16px; border-radius: 8px; border: 1px solid transparent; font-size: 13px;
  font-weight: 600; cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f0f1f3; }
.btn-danger { background: #fdeceb; color: var(--danger); border-color: #f6cfcc; }
.btn-danger:hover { background: #fbdad7; }
.btn-block { width: 100%; margin-top: 18px; padding: 11px; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ---------- Balances grid ---------- */
.balances-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.balance-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; cursor: pointer; transition: box-shadow .15s, transform .15s;
}
.balance-card:hover { box-shadow: 0 6px 18px rgba(20,30,60,.08); transform: translateY(-1px); }
.balance-card h3 { margin: 0 0 10px; font-size: 15px; }
.balance-total { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.balance-total.positive { color: var(--danger); }
.balance-total.negative { color: var(--success); }
.balance-total.zero { color: var(--text-muted); }
.balance-sub { font-size: 12px; color: var(--text-muted); }
.balance-pills { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 20px; }
.pill { background: #eef1f6; border-radius: 20px; padding: 6px 14px; font-size: 13px; font-weight: 600; }

.type-badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .02em; background: #eef1f6; color: var(--text-muted); }
.type-badge.type-invoice { background: #fdeceb; color: var(--danger); }
.type-badge.type-payment { background: #e8f7ef; color: var(--success); }

.opening-balance-row { background: #f7f8fa; font-style: italic; }
.opening-balance-row td { color: var(--text-muted); }

/* ---------- Table ---------- */
.data-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.data-table th, .data-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
.data-table th { background: #f9fafb; color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #fafbfc; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.tab-link { background: none; border: none; padding: 9px 14px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; }
.tab-link.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 20, 35, .45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: #fff; border-radius: var(--radius); padding: 26px 26px 20px; width: 420px; max-width: 92vw;
  max-height: 88vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,.2);
}
.modal h3 { margin: 0 0 16px; font-size: 17px; }
.modal label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
.modal input, .modal select, .modal textarea {
  width: 100%; padding: 9px 10px; border: 1px solid var(--border); border-radius: 7px; font-size: 13px; font-family: inherit;
}
.modal textarea { resize: vertical; min-height: 60px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.field-error { color: var(--danger); font-size: 12px; min-height: 16px; margin-top: 8px; }
.field-hint { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

.password-input-group { display: flex; gap: 8px; align-items: center; }
.password-input-group input { flex: 1 1 auto; }
.password-input-group button { flex: 0 0 auto; white-space: nowrap; padding: 9px 12px; font-size: 12px; }

.permissions-grid { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.checkbox-label { display: flex !important; align-items: center; gap: 8px; font-weight: 400 !important; margin: 0 !important; cursor: pointer; }
.checkbox-label input[type="checkbox"] { width: auto; }

#view-company-profile h3 { font-size: 15px; margin: 22px 0 10px; }
#view-company-profile textarea { width: 100%; max-width: 520px; padding: 9px 10px; border: 1px solid var(--border); border-radius: 7px; font-size: 13px; font-family: inherit; resize: vertical; }
.profile-actions { justify-content: flex-start; margin-top: 10px; }
.profile-upload-row { margin-bottom: 12px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #1f2430; color: #fff; padding: 11px 20px; border-radius: 8px; font-size: 13px; z-index: 100;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

.muted { color: var(--text-muted); }
.link-btn { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 13px; font-weight: 600; padding: 0; }
.link-btn.danger { color: var(--danger); }

/* ---------- Uploaded/downloaded-by hint ---------- */
.file-meta { color: var(--text-muted); font-size: 11px; margin-top: 2px; }

/* ---------- "Sistemə daxil edildi" / "Qarşı tərəfə çatdı" checkbox xanası ---------- */
.checkbox-cell { display: inline-flex; align-items: center; cursor: pointer; }
.checkbox-cell input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; }

/* ---------- Orders: category badge ---------- */
.category-badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .02em; }
.category-badge.category-gold { background: #fdf3d8; color: #97690a; }
.category-badge.category-oasis { background: #dcf3f3; color: #147a7a; }

/* ---------- Access requests: status badge ---------- */
.status-badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .02em; }
.status-badge.status-pending { background: #fdf3d8; color: #97690a; }
.status-badge.status-approved { background: #dcf3e3; color: #147a45; }

/* ---------- Sticky notes (dashboard board) ---------- */
.notes-header { display: flex; align-items: center; justify-content: space-between; margin: 28px 0 14px; }
.notes-header h3 { margin: 0; font-size: 16px; }
.notes-board { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.note-card {
  position: relative; border-radius: 8px; padding: 14px 16px 12px; min-height: 90px;
  box-shadow: 0 4px 12px rgba(20, 30, 60, .06); display: flex; flex-direction: column; justify-content: space-between;
}
.note-card .note-body { font-size: 13px; white-space: pre-wrap; word-break: break-word; margin-bottom: 10px; }
.note-card .note-author { font-size: 11px; font-weight: 700; opacity: .65; }
.note-delete {
  position: absolute; top: 6px; right: 8px; background: none; border: none; cursor: pointer;
  font-size: 16px; line-height: 1; color: inherit; opacity: .5; padding: 2px;
}
.note-delete:hover { opacity: 1; }
.note-yellow { background: #fdf3c7; }
.note-green { background: #d7f2df; }
.note-blue { background: #d9e8fb; }
.note-pink { background: #fbdbe8; }
.note-purple { background: #e6ddf9; }

/* ---------- Floating chat (bütün ekranlarda sağ-alt küncdə) ---------- */
.chat-fab {
  position: fixed; bottom: 24px; right: 24px; width: 54px; height: 54px; border-radius: 50%;
  background: var(--primary); color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 22px rgba(47, 111, 237, .38); z-index: 90; transition: transform .12s, background .12s;
}
.chat-fab:hover { background: var(--primary-dark); transform: translateY(-2px); }
.chat-fab.has-unread::after {
  content: ''; position: absolute; top: 2px; right: 2px; width: 13px; height: 13px;
  border-radius: 50%; background: #ff3b30; border: 2px solid var(--surface);
}

.chat-panel {
  position: fixed; bottom: 24px; right: 24px; width: 320px; height: 440px; max-width: calc(100vw - 32px);
  max-height: calc(100vh - 48px); background: var(--surface); border-radius: 14px; overflow: hidden;
  box-shadow: 0 16px 44px rgba(15, 20, 35, .22); display: flex; flex-direction: column; z-index: 90;
}
.chat-panel-header {
  background: var(--primary); color: #fff; padding: 12px 14px; display: flex; align-items: center;
  gap: 8px; font-size: 14px; font-weight: 700; flex-shrink: 0;
}
.chat-panel-header select {
  flex: 1; min-width: 0; font-size: 12px; padding: 5px 6px; border-radius: 6px; border: none;
  font-family: inherit; background: rgba(255,255,255,.92); color: var(--text);
}
.chat-minimize {
  background: none; border: none; color: #fff; font-size: 20px; line-height: 1; cursor: pointer;
  padding: 0 2px; opacity: .85; flex-shrink: 0;
}
.chat-minimize:hover { opacity: 1; }
.chat-messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; background: var(--bg); }
.chat-message { max-width: 82%; background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 7px 11px; align-self: flex-start; }
.chat-message.chat-mine { align-self: flex-end; background: #dbe7fd; border-color: #c4d9fb; }
.chat-message-meta { font-size: 10px; font-weight: 700; color: var(--text-muted); margin-bottom: 1px; }
.chat-message-body { font-size: 12px; white-space: pre-wrap; word-break: break-word; }
.chat-input-row { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--border); flex-shrink: 0; background: var(--surface); }
.chat-input-row input { flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--border); border-radius: 20px; font-size: 12px; }
.chat-send-btn {
  width: 34px; height: 34px; border-radius: 50%; border: none; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0;
}
.chat-send-btn:hover { background: var(--primary-dark); }

@media (max-width: 760px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 10px 14px; overflow-x: auto; }
  .sidebar nav { flex-direction: row; }
  .sidebar-footer { display: none; }
  .content { padding: 18px; }
  .chat-fab { bottom: 16px; right: 16px; }
  .chat-panel { bottom: 0; right: 0; width: 100%; height: 100%; max-width: 100vw; max-height: 100vh; border-radius: 0; }
}
