/* Mobile-first responsive CSS for time tracking app */

:root {
  --gap: 12px;
  --primary-color: #0066cc;
  --danger-color: #cc0000;
  --success-color: #00aa00;
  --error-color: #cc0000;
  --info-color: #0066cc;
  --border-color: #ddd;
  --bg-light: #f5f5f5;
  --text-color: #333;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text-color);
  background: var(--bg-light);
}

/* Navigation */
nav {
  background: var(--primary-color);
  padding: 0.5rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

nav a {
  color: white;
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  flex-shrink: 0;
}

nav a:hover,
nav a:focus {
  background: rgba(255, 255, 255, 0.2);
  outline: 2px solid white;
}

/* Main content */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

h1, h2, h3, h4 {
  margin-top: 0;
  margin-bottom: 1rem;
}

h1 {
  font-size: 1.65rem;
}

h2 {
  font-size: 1.5rem;
}

section {
  background: white;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Flash messages */
.flash {
  padding: 1rem;
  margin-bottom: 1rem;
  border-radius: 4px;
  font-weight: 500;
}

.flash-success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.flash-error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.flash-info {
  background: #d1ecf1;
  color: #0c5460;
  border: 1px solid #bee5eb;
}

/* Forms */
.form-group {
  margin-bottom: 1rem;
}

label {
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 500;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 0.75rem;
  font-size: 16px; /* Prevents zoom on iOS */
  min-height: 44px; /* Touch-friendly */
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-family: inherit;
  max-width: 100%;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
  background-color: white;
}

/* Date and time inputs - minimal styling to preserve native functionality */
input[type="date"],
input[type="time"] {
  width: 100%;
  padding: 0.5rem;
  font-size: 16px;
  min-height: 44px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  max-width: 100%;
  box-sizing: border-box;
  /* No appearance override - let browser handle it */
}

/* Mobile responsive adjustments */
@media (max-width: 640px) {
  /* Reduce padding on containers to give more room for inputs */
  section {
    padding: 1rem;
  }

  main {
    padding: 0.5rem;
  }

  /* Fix date/time inputs being too wide */
  input[type="date"],
  input[type="time"] {
    padding: 0.5rem 0.25rem !important;
    width: 100% !important;
    max-width: 100% !important;
    font-size: 14px !important; /* Smaller font to fit content */
  }

  /* Ensure form groups don't overflow */
  .form-group {
    max-width: 100%;
    overflow: hidden;
  }

  /* Make sure form-row items don't cause overflow */
  .form-row {
    margin: 0;
  }
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
}

.form-row > * {
  flex: 1 1 100%;
  min-width: 0;
  max-width: 100%;
}

@media (min-width: 640px) {
  .form-row > * {
    flex: 1 1 160px;
    min-width: 160px;
    max-width: none;
  }
}

/* Buttons */
button,
.btn-primary,
.btn-secondary,
.btn-danger {
  padding: 0.75rem 1.5rem;
  min-height: 44px; /* Touch-friendly */
  font-size: 16px;
  font-weight: 500;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

button,
.btn-primary {
  background: var(--primary-color);
  color: white;
}

button:hover,
button:focus,
.btn-primary:hover,
.btn-primary:focus {
  background: #0052a3;
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

.btn-secondary {
  background: #6c757d;
  color: white;
}

.btn-secondary:hover,
.btn-secondary:focus {
  background: #545b62;
  outline: 2px solid #6c757d;
  outline-offset: 2px;
}

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

.btn-danger:hover,
.btn-danger:focus {
  background: #a30000;
  outline: 2px solid var(--danger-color);
  outline-offset: 2px;
}

.form-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Button groups in table cells */
td button,
td form {
  display: inline-block;
  margin-right: 0.5rem;
}

td button:last-child,
td form:last-child {
  margin-right: 0;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

th, td {
  padding: 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

th {
  background: var(--bg-light);
  font-weight: 600;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Mobile table layout */
@media (max-width: 640px) {
  table thead {
    display: none;
  }

  table, tbody, tr, td {
    display: block;
    width: 100%;
  }

  tr {
    margin-bottom: var(--gap);
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 0.5rem;
  }

  td {
    border-bottom: none;
    padding: 0.5rem;
  }

  td::before {
    content: attr(data-label) ": ";
    font-weight: 600;
    display: inline-block;
    min-width: 100px;
  }

  /* Don't show label for actions column */
  td[data-label="Åtgärder"]::before {
    display: none;
  }

  /* Make action buttons display inline on mobile */
  td[data-label="Åtgärder"] {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding-top: 0.5rem;
  }

  td[data-label="Åtgärder"] button,
  td[data-label="Åtgärder"] form {
    margin: 0;
    flex: 0 0 auto;
  }

  td button,
  td form {
    margin-top: 0.5rem;
  }
}

/* Login page */
.login-container {
  max-width: 400px;
  margin: 4rem auto;
  padding: 2rem;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.login-form button {
  width: 100%;
}

/* Active timer display */
.active-timer {
  background: #e7f3ff;
  padding: 1rem;
  border-radius: 4px;
  border-left: 4px solid var(--primary-color);
}

.active-timer p {
  margin: 0.5rem 0;
}

.active-timer form {
  margin-top: 1rem;
}

/* Report summary */
.report-summary {
  margin-top: 2rem;
  padding: 1rem;
  background: var(--bg-light);
  border-radius: 4px;
}

.report-summary h3 {
  margin-top: 0;
}

.report-summary ul {
  list-style: none;
  padding: 0;
}

.report-summary li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-color);
}

.report-summary li:last-child {
  border-bottom: none;
}

.total-summary {
  font-size: 1.125rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 2px solid var(--border-color);
}

.active-filters {
  background: #fff3cd;
  padding: 1rem;
  border-radius: 4px;
  margin-bottom: 1rem;
}

.export-actions {
  margin-top: 1.5rem;
}

/* Modal */
#edit-modal,
#edit-entry-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  align-items: center;
  justify-content: center;
  z-index: 1000;
  display: none; /* Hidden by default */
}

#edit-modal[style*="display: block"],
#edit-entry-modal[style*="display: block"] {
  display: flex !important;
}

.modal-content {
  background: white;
  padding: 2rem;
  border-radius: 8px;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
}

/* Responsive adjustments */
@media (min-width: 768px) {
  h1 {
    font-size: 1.65rem;
  }

  main {
    padding: 2rem;
  }

  section {
    padding: 2rem;
  }
}

/* Print styles */
@media print {
  nav {
    display: none;
  }

  .export-actions,
  .form-actions,
  button,
  .btn-primary,
  .btn-secondary,
  .btn-danger {
    display: none;
  }
}
