/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:       #1a3a5c;
  --blue-mid:   #2c5f8a;
  --blue-light: #e8f0f7;
  --accent:     #d4432a;
  --green:      #2a7d4f;
  --green-lys:  #e6f4ed;
  --yellow:     #f5a623;
  --gray-50:    #f7f8fa;
  --gray-100:   #eef0f3;
  --gray-200:   #dde0e6;
  --gray-400:   #9aa2b0;
  --gray-600:   #5a6472;
  --gray-800:   #2d3340;
  --white:      #ffffff;
  --radius:     8px;
  --shadow:     0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg:  0 4px 24px rgba(0,0,0,0.13);
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ===== LOGIN PAGE ===== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-mid) 100%);
  padding: 1rem;
}

.login-wrap {
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-logo {
  width: 64px; height: 64px;
  background: var(--white);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 1.2rem;
}

.logo-mark {
  font-size: 2rem;
  font-weight: 800;
  color: var(--blue);
}

.login-wrap h1 {
  color: var(--white);
  font-size: 1.7rem;
  font-weight: 700;
  margin-bottom: .25rem;
}

.login-sub {
  color: rgba(255,255,255,.75);
  font-size: .9rem;
  margin-bottom: 1.8rem;
}

/* ===== CARD ===== */
.card {
  background: var(--white);
  border-radius: 12px;
  padding: 2rem;
  box-shadow: var(--shadow-lg);
  text-align: left;
}

.card h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--blue);
  margin-bottom: 1.2rem;
}

/* ===== FORM FIELDS ===== */
.field { margin-bottom: 1rem; }

.field label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: .35rem;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: .65rem .85rem;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: .95rem;
  color: var(--gray-800);
  background: var(--white);
  transition: border-color .15s;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}

.field select {
  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 d='M1 1l5 5 5-5' stroke='%239aa2b0' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .85rem center;
  padding-right: 2.2rem;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--blue-mid);
  box-shadow: 0 0 0 3px rgba(44,95,138,.12);
}

.field textarea { resize: vertical; min-height: 70px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-block;
  width: 100%;
  padding: .75rem 1rem;
  border-radius: var(--radius);
  border: none;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  font-family: inherit;
  text-align: center;
  margin-top: .6rem;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn-primary { background: var(--blue); color: var(--white); }
.btn-primary:hover { background: var(--blue-mid); }
.btn-primary:active { opacity: .85; }

.btn-danger { background: var(--accent); color: var(--white); }
.btn-danger:hover { opacity: .88; }

.btn-success { background: var(--green); color: var(--white); }
.btn-success:hover { opacity: .88; }

.btn-ghost {
  background: transparent;
  color: var(--blue-mid);
  border: 1.5px solid var(--gray-200);
}
.btn-ghost:hover { background: var(--gray-50); }

.btn-sm {
  width: auto;
  padding: .45rem .9rem;
  font-size: .82rem;
  margin-top: 0;
}

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

/* ===== MESSAGES ===== */
.error-msg {
  background: #fdecea;
  color: var(--accent);
  border-radius: var(--radius);
  padding: .6rem .85rem;
  font-size: .88rem;
  margin-bottom: .6rem;
}

.success-msg {
  background: var(--green-lys);
  color: var(--green);
  border-radius: var(--radius);
  padding: .6rem .85rem;
  font-size: .88rem;
  margin-bottom: .6rem;
}

.hint {
  color: var(--gray-600);
  font-size: .88rem;
  margin-bottom: 1rem;
}

.hidden { display: none !important; }

/* ===== APP LAYOUT ===== */
.app-layout {
  display: grid;
  grid-template-rows: 56px 1fr;
  min-height: 100vh;
}

/* ===== TOPBAR ===== */
.topbar {
  background: var(--blue);
  color: var(--white);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: .75rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}

.topbar-logo {
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: -.01em;
  white-space: nowrap;
}

.topbar-title {
  color: rgba(255,255,255,.7);
  font-size: .82rem;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-user {
  font-size: .78rem;
  color: rgba(255,255,255,.7);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
  display: none;
}

@media (min-width: 500px) {
  .topbar-user { display: block; }
}

.topbar-logout {
  background: rgba(255,255,255,.12);
  color: var(--white);
  border: none;
  border-radius: var(--radius);
  padding: .4rem .75rem;
  font-size: .82rem;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.topbar-logout:hover { background: rgba(255,255,255,.22); }

/* ===== MAIN CONTENT ===== */
.main-content {
  padding: 1.25rem 1rem;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

@media (min-width: 600px) {
  .main-content { padding: 2rem 1.5rem; }
}

/* ===== TABS ===== */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--gray-200);
  margin-bottom: 1.5rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  padding: .6rem .9rem;
  border: none;
  background: none;
  font-size: .88rem;
  font-weight: 600;
  color: var(--gray-600);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
  font-family: inherit;
  white-space: nowrap;
  flex-shrink: 0;
}

.tab.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ===== STATS ROW ===== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: .75rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--gray-400);
  margin-bottom: .3rem;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--blue);
  line-height: 1;
}

.stat-value.positive { color: var(--green); }
.stat-value.negative { color: var(--accent); }

/* ===== TABLE ===== */
.table-wrap {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
  min-width: 480px;
}

thead th {
  background: var(--blue);
  color: var(--white);
  font-weight: 600;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: .7rem .9rem;
  text-align: left;
  white-space: nowrap;
}

tbody tr { border-bottom: 1px solid var(--gray-100); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--gray-50); }

tbody td {
  padding: .65rem .9rem;
  color: var(--gray-800);
  vertical-align: middle;
}

/* Handling-kolonne på mobil: stabling av knapper */
tbody td:last-child {
  white-space: nowrap;
}

/* ===== BADGE ===== */
.badge {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-green  { background: var(--green-lys); color: var(--green); }
.badge-red    { background: #fdecea; color: var(--accent); }
.badge-blue   { background: var(--blue-light); color: var(--blue); }
.badge-yellow { background: #fef7e6; color: #8a6000; }

/* ===== SECTION HEADER ===== */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: .5rem;
}

.section-header h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--blue);
}

/* ===== FORM CARD ===== */
.form-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

@media (min-width: 600px) {
  .form-card { padding: 1.5rem; }
}

.form-card h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--blue);
  margin-bottom: 1.2rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: .75rem;
}

@media (min-width: 560px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
}

.form-grid .field { margin-bottom: 0; }
.form-grid .field.full { grid-column: 1 / -1; }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--gray-400);
}

.empty-state p { font-size: .95rem; }

/* ===== MODAL OVERLAY ===== */
[style*="position:fixed"] .card {
  max-height: 90vh;
  overflow-y: auto;
}

/* ===== KNAPPER PÅ MOBIL ===== */
@media (max-width: 500px) {
  .btn-sm {
    padding: .5rem .7rem;
    font-size: .78rem;
  }

  .stat-value { font-size: 1.5rem; }

  table { min-width: 380px; }
}
